动态生成HTML表单

来源:百度文库 编辑:神马文学网 时间:2024/04/27 14:54:31
动态生成HTML表单
前段时间在做设票系统,瞎搞一会,用JavaScript搞了一些有趣的东西,因为投票的条数不定,一个题目有不定条选项,要实现一次把投票题目与不定数目选项的投票项目一次性添加进数据库,因些就想了用JavaScript写了一个动态生成的HTML的“文体框”。然后用数组把所有值写入数据库。现在就把它做成一个简单的演示例子放在这里吧:


 动态生成文体框演示 title><br><img style='max-width:300px;' id="img3" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><br><img style='max-width:300px;' id="img4" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><br><img style='max-width:300px;' id="img5" src="http://image.360doc.cn/DownloadImg/10754/331254_6.gif" /><img style='max-width:300px;' id="img6" src="http://image.360doc.cn/DownloadImg/10754/331254_7.gif" /><script language="javascript"><img style='max-width:300px;' id="img7" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" /><br><img style='max-width:300px;' id="img8" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" /><br><img style='max-width:300px;' id="img9" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />    function createitem()<br><img style='max-width:300px;' id="img10" src="http://image.360doc.cn/DownloadImg/10754/331254_11.gif" /><img style='max-width:300px;' id="img11" src="http://image.360doc.cn/DownloadImg/10754/331254_12.gif" />    <img style='max-width:300px;' id="img12" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" />{<br><img style='max-width:300px;' id="img13" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />       var m=document.form1;<br><img style='max-width:300px;' id="img14" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />       var val=m.max.value;<br><img style='max-width:300px;' id="img15" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />       for (i=0;i<val;i++)<br><img style='max-width:300px;' id="img16" src="http://image.360doc.cn/DownloadImg/10754/331254_11.gif" /><img style='max-width:300px;' id="img17" src="http://image.360doc.cn/DownloadImg/10754/331254_12.gif" />       <img style='max-width:300px;' id="img18" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" />{<br><img style='max-width:300px;' id="img19" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />               r=tab.insertRow()<br><img style='max-width:300px;' id="img20" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" /><br><img style='max-width:300px;' id="img21" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />            c=r.insertCell(‘nowrap align:Left‘)<br><img style='max-width:300px;' id="img22" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />            c.innerHTML="复选单选";<br><img style='max-width:300px;' id="img23" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" /><br><img style='max-width:300px;' id="img24" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />            c=r.insertCell()<br><img style='max-width:300px;' id="img25" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />            c.innerHTML="·";<br><img style='max-width:300px;' id="img26" src="http://image.360doc.cn/DownloadImg/10754/331254_27.gif" />       }<br><img style='max-width:300px;' id="img27" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />       m.max.value="";<br><img style='max-width:300px;' id="img28" src="http://image.360doc.cn/DownloadImg/10754/331254_27.gif" />    }<br><img style='max-width:300px;' id="img29" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" /><br><img style='max-width:300px;' id="img30" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />    function resetDate()<br><img style='max-width:300px;' id="img31" src="http://image.360doc.cn/DownloadImg/10754/331254_11.gif" /><img style='max-width:300px;' id="img32" src="http://image.360doc.cn/DownloadImg/10754/331254_12.gif" />    <img style='max-width:300px;' id="img33" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" />{<br><img style='max-width:300px;' id="img34" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />       var m=document.form1;<br><img style='max-width:300px;' id="img35" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />       m.action="butt.html";<br><img style='max-width:300px;' id="img36" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />       m.submit();<br><img style='max-width:300px;' id="img37" src="http://image.360doc.cn/DownloadImg/10754/331254_27.gif" />    }<br><img style='max-width:300px;' id="img38" src="http://image.360doc.cn/DownloadImg/10754/331254_39.gif" /><br><img style='max-width:300px;' id="img39" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />script><br><img style='max-width:300px;' id="img40" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />head><br><img style='max-width:300px;' id="img41" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><br><img style='max-width:300px;' id="img42" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><body><br><img style='max-width:300px;' id="img43" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><form name="form1" method=post action=""><br><img style='max-width:300px;' id="img44" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><table name="tab" id="tab"><br><img style='max-width:300px;' id="img45" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />   <tr><br><img style='max-width:300px;' id="img46" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />     <td colspan="2"> <div align="center">·动态生成文体框演示·div>td><br><img style='max-width:300px;' id="img47" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />   tr><br><img style='max-width:300px;' id="img48" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><br><img style='max-width:300px;' id="img49" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />   <tr><br><img style='max-width:300px;' id="img50" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />     <td colspan="2"> 请输入您要添加的行数:<br><img style='max-width:300px;' id="img51" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />       <input type="text" name="max" size="5" value=""><br><img style='max-width:300px;' id="img52" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />       <input type="button" name="add" value="添加" onclick="createitem()"><br><img style='max-width:300px;' id="img53" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />       <input type="button" name="reset" value="重置" onclick="resetDate()"><br><img style='max-width:300px;' id="img54" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />     td><br><img style='max-width:300px;' id="img55" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />   tr><br><img style='max-width:300px;' id="img56" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />table><br><img style='max-width:300px;' id="img57" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />form><br><img style='max-width:300px;' id="img58" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />body><br><img style='max-width:300px;' id="img59" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><br><img style='max-width:300px;' id="img60" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />html><br><img style='max-width:300px;' id="img61" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><br>后来又做了一些其它的尝试演示,下面这个程序是增加了删除HTML表单的例子:<br><img style='max-width:300px;' id="img62" src="http://image.360doc.cn/DownloadImg/10754/331254_6.gif" /><img style='max-width:300px;' id="img63" src="http://image.360doc.cn/DownloadImg/10754/331254_7.gif" /><script language="javascript"><img style='max-width:300px;' id="img64" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" /><br><img style='max-width:300px;' id="img65" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />    var curRow=null;<br><img style='max-width:300px;' id="img66" src="http://image.360doc.cn/DownloadImg/10754/331254_11.gif" /><img style='max-width:300px;' id="img67" src="http://image.360doc.cn/DownloadImg/10754/331254_12.gif" />    function selectRow(tr1)<img style='max-width:300px;' id="img68" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" />{<br><img style='max-width:300px;' id="img69" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />        if(curRow)<br><img style='max-width:300px;' id="img70" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />        curRow.bgColor="#FFFFFF";<br><img style='max-width:300px;' id="img71" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />        tr1.bgColor="e7e7e7";<br><img style='max-width:300px;' id="img72" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />        curRow=tr1;<br><img style='max-width:300px;' id="img73" src="http://image.360doc.cn/DownloadImg/10754/331254_27.gif" />    }<br><img style='max-width:300px;' id="img74" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" /><br><img style='max-width:300px;' id="img75" src="http://image.360doc.cn/DownloadImg/10754/331254_11.gif" /><img style='max-width:300px;' id="img76" src="http://image.360doc.cn/DownloadImg/10754/331254_12.gif" />    function addRow(src)<img style='max-width:300px;' id="img77" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" />{<br><img style='max-width:300px;' id="img78" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />        var newrow = src.insertRow(src.rows.length-1);<br><img style='max-width:300px;' id="img79" src="http://image.360doc.cn/DownloadImg/10754/331254_11.gif" /><img style='max-width:300px;' id="img80" src="http://image.360doc.cn/DownloadImg/10754/331254_12.gif" />        newrow.attachEvent("onclick",function()<img style='max-width:300px;' id="img81" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" />{selectRow(newrow);});<br><img style='max-width:300px;' id="img82" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />        newrow.height=20;<br><img style='max-width:300px;' id="img83" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />        var i=5;<br><img style='max-width:300px;' id="img84" src="http://image.360doc.cn/DownloadImg/10754/331254_11.gif" /><img style='max-width:300px;' id="img85" src="http://image.360doc.cn/DownloadImg/10754/331254_12.gif" />        while(i--)<img style='max-width:300px;' id="img86" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" />{<br><img style='max-width:300px;' id="img87" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />            var newcell = newrow.insertCell();<br><img style='max-width:300px;' id="img88" src="http://image.360doc.cn/DownloadImg/10754/331254_11.gif" /><img style='max-width:300px;' id="img89" src="http://image.360doc.cn/DownloadImg/10754/331254_12.gif" />            switch(i)<img style='max-width:300px;' id="img90" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" />{<br><img style='max-width:300px;' id="img91" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />                case 0: newcell.innerHTML= ‘<input type="button" onClick="javascript:delRow(this.parentElement.parentElement)" value="删除此行">‘;break;<br><img style='max-width:300px;' id="img92" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />                default: newcell.innerHTML=‘ ‘;break;<br><img style='max-width:300px;' id="img93" src="http://image.360doc.cn/DownloadImg/10754/331254_27.gif" />            }<br><img style='max-width:300px;' id="img94" src="http://image.360doc.cn/DownloadImg/10754/331254_27.gif" />        }<br><img style='max-width:300px;' id="img95" src="http://image.360doc.cn/DownloadImg/10754/331254_27.gif" />    }<br><img style='max-width:300px;' id="img96" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" /><br><img style='max-width:300px;' id="img97" src="http://image.360doc.cn/DownloadImg/10754/331254_11.gif" /><img style='max-width:300px;' id="img98" src="http://image.360doc.cn/DownloadImg/10754/331254_12.gif" />    function delRow(src)<img style='max-width:300px;' id="img99" src="http://image.360doc.cn/DownloadImg/10754/331254_8.gif" />{<br><img style='max-width:300px;' id="img100" src="http://image.360doc.cn/DownloadImg/10754/331254_9.gif" />        src.parentElement.deleteRow(src.rowIndex);<br><img style='max-width:300px;' id="img101" src="http://image.360doc.cn/DownloadImg/10754/331254_39.gif" />    }<br><img style='max-width:300px;' id="img102" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />script><br><img style='max-width:300px;' id="img103" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><br><img style='max-width:300px;' id="img104" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><table id="tabe" width="100%"  border="1" ><br><img style='max-width:300px;' id="img105" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />  <tr><br><img style='max-width:300px;' id="img106" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />    <th width="20%">编号th><br><img style='max-width:300px;' id="img107" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />    <th width="20%">姓名th><br><img style='max-width:300px;' id="img108" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />    <th width="20%">性别th><br><img style='max-width:300px;' id="img109" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />    <th width="20%">年龄th><br><img style='max-width:300px;' id="img110" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />    <th width="20%">民族th><br><img style='max-width:300px;' id="img111" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />  tr><br><img style='max-width:300px;' id="img112" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><br><img style='max-width:300px;' id="img113" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />  <tr id="lastRow" onClick="addRow(this.parentElement)"><br><img style='max-width:300px;' id="img114" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />    <td> 1td><br><img style='max-width:300px;' id="img115" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />    <td> 2td><br><img style='max-width:300px;' id="img116" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />    <td> 3td><br><img style='max-width:300px;' id="img117" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />    <td> 4td><br><img style='max-width:300px;' id="img118" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />    <td> 5td><br><img style='max-width:300px;' id="img119" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />  tr><br><img style='max-width:300px;' id="img120" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" /><br><img style='max-width:300px;' id="img121" src="http://image.360doc.cn/DownloadImg/10754/331254_1.gif" />table></div> <div class="list-group"> <a href="/article/100236" class="list-group-item">动态生成HTML表单</a> <a href="/article/393418" class="list-group-item">动态生成HTML表单</a> <a href="/article/1583831" class="list-group-item">动态生成HTML表单 - Alpha - BlogJava</a> <a href="/article/77131" class="list-group-item">HTML表单(Forms)</a> <a href="/article/1778083" class="list-group-item">HTML 表单和输入</a> <a href="/article/2090048" class="list-group-item">生成HTML的方法</a> <a href="/article/880" class="list-group-item">用DHTML实现动态表单</a> <a href="/article/100839" class="list-group-item">HTML表单(Forms)-HTML教程 网页教程与代码</a> <a href="/article/1869390" class="list-group-item">ASP和HTML表单 (ASP and HTML Forms)</a> <a href="/article/57584" class="list-group-item">通用asp生成html代码</a> <a href="/article/57585" class="list-group-item">ASP生成HTML-另一篇</a> <a href="/article/57587" class="list-group-item">使用ASP生成HTML文件</a> <a href="/article/123498" class="list-group-item">通用asp生成html代码</a> <a href="/article/2090069" class="list-group-item">js生成html的方法</a> <a href="/article/2370165" class="list-group-item">通用asp生成html代码</a> <a href="/article/2719159" class="list-group-item">html中的表单,actioon ,method,fieldset-凡夫-家园博客</a> <a href="/article/57586" class="list-group-item">实例演示:使用ASP生成HTML文件</a> <a href="/article/943806" class="list-group-item">通用asp生成html代码--学无止境</a> <a href="/article/1949252" class="list-group-item">动态生成与编译(八)----动态编译</a> <a href="/article/5377" class="list-group-item">asp取动态表单中数据并写入xml文件</a> <a href="/article/1522070" class="list-group-item">asp取动态表单中数据并写入xml文</a> <a href="/article/1949246" class="list-group-item">动态生成与编译(七)----根据CodeDOM生成源代码</a> <a href="/article/2019839" class="list-group-item">PHP中动态HTML的输出技术</a> <a href="/article/20412" class="list-group-item">动态网站首页的静态生成方法</a> </div> </div> </div> </div> </div> </div> <footer id="footer" class="footer hidden-print"> <div class="container"> <div class="panel panel-default"> <div class="panel-heading">相关问题</div> <div class="panel-body"> <a class="btn btn-default" href="/article/215204" title="蓝田国土局盖豪华别墅续:市纪委已进驻蓝田(三秦都市报 2007-12-4)">蓝田国土局盖豪华别墅续:市纪委已进驻蓝田(三秦都市报 2007-12-4)</a> <a class="btn btn-default" href="/article/215205" title="蓝田国土局9别墅系非法建筑 县委称坚决纠正(三秦都市报 2007-12-5)">蓝田国土局9别墅系非法建筑 县委称坚决纠正(三秦都市报 2007-12-5)</a> <a class="btn btn-default" href="/article/215206" title="〖motto〗哈佛图书馆自习室墙上的训言">〖motto〗哈佛图书馆自习室墙上的训言</a> <a class="btn btn-default" href="/article/215207" title="石 磨">石 磨</a> <a class="btn btn-default" href="/article/215208" title="中国最“牛”公章 看得见摸得着的民主(贵州政协报 2007-12-4)">中国最“牛”公章 看得见摸得着的民主(贵州政协报 2007-12-4)</a> <a class="btn btn-default" href="/article/215209" title="你现在的努力与坚持为了度过未来的难关">你现在的努力与坚持为了度过未来的难关</a> <a class="btn btn-default" href="/article/215210" title="毕诗成:“最牛公章”牛在最直接的分权制衡(华商报 2007-12-5)">毕诗成:“最牛公章”牛在最直接的分权制衡(华商报 2007-12-5)</a> <a class="btn btn-default" href="/article/215211" title="好看簿 - Web2.0社会生态网络交往分析">好看簿 - Web2.0社会生态网络交往分析</a> <a class="btn btn-default" href="/article/215212" title="IP存储前沿:iSCSI技术之彻底剖析篇_51CTO.COM">IP存储前沿:iSCSI技术之彻底剖析篇_51CTO.COM</a> <a class="btn btn-default" href="/article/215213" title="王攀:“最牛公章”告诉我们什么是民主(工人日报 2007-12-6)">王攀:“最牛公章”告诉我们什么是民主(工人日报 2007-12-6)</a> <a class="btn btn-default" href="/article/215214" title="曹林:“禁止养猪”既不合法又不合理(新京报 2007-12-6)">曹林:“禁止养猪”既不合法又不合理(新京报 2007-12-6)</a> <a class="btn btn-default" href="/article/215215" title="未来始于现在:学校2.0宣言1">未来始于现在:学校2.0宣言1</a> <a class="btn btn-default" href="/article/215216" title="杨耕身:拥有表达权的民众才不受愚弄(新京报 2007-12-4)">杨耕身:拥有表达权的民众才不受愚弄(新京报 2007-12-4)</a> <a class="btn btn-default" href="/article/215217" title="骗杀矿工假冒亲戚领钱(新京报 2007-12-6)">骗杀矿工假冒亲戚领钱(新京报 2007-12-6)</a> <a class="btn btn-default" href="/article/215218" title="吴祚来:圆明园到底是谁家的园林?(新京报 2007-12-6)">吴祚来:圆明园到底是谁家的园林?(新京报 2007-12-6)</a> <a class="btn btn-default" href="/article/215219" title="好看簿 - 网络学习和交流: 跨出第一步">好看簿 - 网络学习和交流: 跨出第一步</a> <a class="btn btn-default" href="/article/215220" title="好看簿 - 我对Blog、Google notebook and Twitter的体会">好看簿 - 我对Blog、Google notebook and Twitter的体会</a> <a class="btn btn-default" href="/article/215221" title="揭密女星和她们干爹的暧昧关系">揭密女星和她们干爹的暧昧关系</a> <a class="btn btn-default" href="/article/215222" title="设计名言 - 第8音 Design Everying">设计名言 - 第8音 Design Everying</a> <a class="btn btn-default" href="/article/215223" title="林彪如何执掌东北帅权">林彪如何执掌东北帅权</a> <a class="btn btn-default" href="/article/215224" title="让小偷也尝点苦头">让小偷也尝点苦头</a> <a class="btn btn-default" href="/article/215225" title="好看簿 - 图解RSS服务">好看簿 - 图解RSS服务</a> <a class="btn btn-default" href="/article/215226" title=":陈赓与蒋介石、林彪恩怨始末(图)">:陈赓与蒋介石、林彪恩怨始末(图)</a> <a class="btn btn-default" href="/article/215227" title="大众三轮摩托车">大众三轮摩托车</a> <a class="btn btn-default" href="/article/215228" title="好看簿 - PKM2007Fall第1周">好看簿 - PKM2007Fall第1周</a> <a class="btn btn-default" href="/article/215229" title="用户体验的要素 - 第8音 Design Everying">用户体验的要素 - 第8音 Design Everying</a> <a class="btn btn-default" href="/article/215230" title="卡片的创意">卡片的创意</a> <a class="btn btn-default" href="/article/215231" title="刺眼的水晶马桶 -">刺眼的水晶马桶 -</a> <a class="btn btn-default" href="/article/215232" title="清理多余的IE右键菜单">清理多余的IE右键菜单</a> <a class="btn btn-default" href="/article/215233" title="小户型房子该如何选购家具?">小户型房子该如何选购家具?</a> <a class="btn btn-default" href="/article/215234" title="好看簿 - PKM2007Fall第4周">好看簿 - PKM2007Fall第4周</a> </div> </div></div> <div class="copy-right"> <p>神马文学网,客观、专业、权威的知识性互动百科全书。</p></div> </footer> </body> </html>