天翎MyApps技术社区 - 低代码平台 | 流程管理系统 | BPM软件

 找回密码
 注册成为天翎用户
查看: 3750|回复: 11

求动态生成表单脚本

[复制链接]
dodo5206 发表于 2011-9-28 01:50:46 | 显示全部楼层 |阅读模式
本帖最后由 shary 于 2011-10-8 13:53 编辑

<html>
<head>
</head>
<script>
function addRow(){
       
        var testTable = document.getElementById("testTable");
        var rows = testTable.getElementsByTagName("tr").length;
        var newRow = testTable.insertRow(rows);
        var cell1 = newRow.insertCell(0);
        cell1.innerHTML="<input id='name"+rows+"' type='text' value='computer"+rows+"'>";
        var cell2 = newRow.insertCell(1);
        cell2.innerHTML="<input id='price"+rows+"' type='text' value='price"+rows+"'>"

}

/**
*  打印数据
*
*/
function printData(){
        //获取数据
        var data = addData();
        //转换成对象
        var dataVar = eval('('+data+')');

        for(var j=0; j<dataVar.length ; j++){
                var values= dataVar[j];
                alert("name:"+values.name+"\n"+"price:"+values.price);
        }
}
/**
*  装载数据
*
*/
function addData(){
        //数据集合
        var datas="[";
        var trs = testTable.getElementsByTagName("TR");

        var rows = testTable.getElementsByTagName("TR").length;
        //因为有表头所以从第二行开始是数据
        for(var i = 1; i < rows ; i++){
                //一对数据
                var data ="";
                var tr = trs;
                if(i==1){
                        data += "{";
                }else{
                        data += ",{";
                }
                var name = tr.firstChild.firstChild.value;
                var price = tr.lastChild.firstChild.value;
                data += "name:'"+name+"',price:'"+price+"'}";
                datas +=data;
        }
        datas += "]";
        //alert(datas);
        return datas;
}
</script>
<body>
<form>
        <input name="button" type="button" id="1" onClick="addRow()" value="增加一行"/>
        <table id="testTable">
        <input name="button2" type="button" id="2" onClick="printData()" value="打印数据"/>
                <tr>
                        <th>笔记本</th>
                        <th>价格</th>
                </tr>
                <tr>
                        <td>
                                <input id="name0" type="text" value='compute1'>
                        </td>
                        <td>

                                <input id="price0" type="text"  value='price1'>
                        </td>
                </tr>
                <tr>
                        <td>
                                <input id="name1" type="text"  value='compute2'>
                        </td>
                        <td>

                                <input id="price1" type="text"  value='price2'>
                        </td>
                </tr>
                <tr>
                        <td>
                                <input id="name2" type="text" value='compute3'>
                        </td>
                        <td>

                                <input id="price2" type="text"  value='price3'>
                        </td>
                </tr>
        <table>
</form>
</body>
</html>


类似这个的功能
admin 发表于 2011-9-28 08:46:59 | 显示全部楼层
您好,平台的计算脚本控件支持Html元素。只是最后需要以一个字符串的形式返回。类似:
var str="<input type='text' name=aa>";
str;
 楼主| dodo5206 发表于 2011-9-28 10:41:54 | 显示全部楼层
你好,可能我表达错误,我的意思是要这个功能的脚本,谢谢
bonnie 发表于 2011-9-28 11:48:42 | 显示全部楼层
您做参考这段脚本吧:        function init(){
                        //中间列
                var table = "<table>";       
table += "<tr><td>No..</td><td>商品编号</td><td>商品全名</td><td>单位</td><td>规格</td><td>数量</td><td>单价</td><td>金额</td><td>扣率</td><td>折后单价</td><td>折后金额</td><td>已发货数量</td><td>备注</td><td>未完成订货数量</td><td></td></tr>";
                        for(var i=1;i<18;i++){
                                var count=i>9 ? i""+i);
                                var tr="<tr><td>"+count+"</td><td><input type='text'/></td><td><input type='text'/></td><td><input type='text'/></td><td><input type='text'/></td><td><input type='text'/></td><td><input type='text'/></td><td><input type='text'/></td><td><input type='text' value='1'/></td><td><input type='text'/></td><td><input type='text'/></td><td><input type='text'/></td><td><input type='text'/></td><td><img src='bt_del.gif' onclick='delRow(this)'/></td></tr>";
                                table +=tr;
                        }
                               
                        //合计地方
                        var totalRow="<tr><td>合计</td><td>0</td><td>0</td><td>0</td></tr>";
                        table +=totalRow;
                       
        table +="</table>";
return table;
       
                }
gongjiacong 发表于 2011-9-28 14:53:37 | 显示全部楼层
var a="<p><select id='11e0-e99b-2c6c42c5-bd1f-ff8278151697' class='cn.myapps.core.dynaform.form.ejb.SelectField' classname='cn.myapps.core.dynaform.form.ejb.SelectField' valueScript='' calculateOnRefresh='false' printHiddenValue='' hiddenValue='' readonlyScript='' hiddenPrintScript='' hiddenScript='' validateRule='' validateLibs='' processDescription='[];[]' editMode='' refreshOnChanged='false' textType='text' filtercondition='' mobile='true' discript='selectTextBox' fieldtype='VALUE_TYPE_VARCHAR' optionsScript=' ;收费;烹调' name='selectTextBox'></select></p>";

a;

恩 这是是我写在 计算脚本中的代码  下拉框可以看到 可是里面的值显示不出来,这个应该怎么该一下啊
shary 发表于 2011-9-28 15:16:40 | 显示全部楼层
你就普通的html元素中写下拉框那样就行了。咋看着那么复杂。
gongjiacong 发表于 2011-9-28 15:21:45 | 显示全部楼层
我是用平台的下来框写的一个,然后把它的源代码复制过来的啊, 那我自己写平台支持吗
shary 发表于 2011-9-28 15:24:32 | 显示全部楼层
计算脚本支持普通html元素的。最后返回一个字符串就可以了。
gongjiacong 发表于 2011-9-28 15:54:36 | 显示全部楼层
那我这个怎么不行啊,

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册成为天翎用户

x
shary 发表于 2011-9-28 16:00:40 | 显示全部楼层
您老人家能用字符串拼接的方式不?
a+="<option >...."把这段html拼接成字符串。

本版积分规则

QQ|手机版|天翎MyApps技术社区 ( 粤ICP备11093750号 )

GMT+8, 2026-8-12 12:35

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表