动态生成HTML表单 - Alpha - BlogJava

来源:百度文库 编辑:神马文学网 时间:2024/04/28 02:30:11
动态生成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/1583831" class="list-group-item">动态生成HTML表单 - Alpha - BlogJava</a> <a href="/article/100236" class="list-group-item">动态生成HTML表单</a> <a href="/article/393418" class="list-group-item">动态生成HTML表单</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/133416" class="list-group-item">[原创]HTML表格分页 - 蜗牛的JAVA外壳 - BlogJava</a> <a href="/article/1203453" class="list-group-item">[原创]HTML表格分页 - 蜗牛的JAVA外壳 - BlogJava</a> <a href="/article/1949252" class="list-group-item">动态生成与编译(八)----动态编译</a> <a href="/article/20541" class="list-group-item">BlogJava</a> <a href="/article/23815" class="list-group-item">BlogJava</a> <a href="/article/5377" class="list-group-item">asp取动态表单中数据并写入xml文件</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/407231" title="一本没有重复字的书《千字文》,不信你读读,找到重复字,你乃高人。">一本没有重复字的书《千字文》,不信你读读,找到重复字,你乃高人。</a> <a class="btn btn-default" href="/article/407232" title="浮华背后:这些上海女人 拎着LV包坐公交车">浮华背后:这些上海女人 拎着LV包坐公交车</a> <a class="btn btn-default" href="/article/407233" title="美国《新闻周刊》:世界为什么向中国低头">美国《新闻周刊》:世界为什么向中国低头</a> <a class="btn btn-default" href="/article/407234" title="国学网--中国经济史论坛 - 2005年中国近代史论著目录·著作·经济、社会、思想、文化">国学网--中国经济史论坛 - 2005年中国近代史论著目录·著作·经济、社会、思想、文化</a> <a class="btn btn-default" href="/article/407235" title="快乐女声周末发力 五一至今地面报名破五万">快乐女声周末发力 五一至今地面报名破五万</a> <a class="btn btn-default" href="/article/407236" title="出尔反尔">出尔反尔</a> <a class="btn btn-default" href="/article/407237" title="杭州飙车案:民意仍在期待被说服">杭州飙车案:民意仍在期待被说服</a> <a class="btn btn-default" href="/article/407238" title="王老吉夏枯草纷争反倒彰显了民族品牌魅力 - 汤祚飞 - 解读 - 价值中国网:网络就是社会...">王老吉夏枯草纷争反倒彰显了民族品牌魅力 - 汤祚飞 - 解读 - 价值中国网:网络就是社会...</a> <a class="btn btn-default" href="/article/407239" title="原来男女有这么大的差别(组图)">原来男女有这么大的差别(组图)</a> <a class="btn btn-default" href="/article/407240" title="被中国人误传了数千年的7句话">被中国人误传了数千年的7句话</a> <a class="btn btn-default" href="/article/407241" title="十大语文差错">十大语文差错</a> <a class="btn btn-default" href="/article/407242" title="广东江门警方以破坏生产为由拘留上访农民/图">广东江门警方以破坏生产为由拘留上访农民/图</a> <a class="btn btn-default" href="/article/407243" title="装修书房位置与颜色选择(图)">装修书房位置与颜色选择(图)</a> <a class="btn btn-default" href="/article/407244" title="最最爱同桌">最最爱同桌</a> <a class="btn btn-default" href="/article/407245" title="送给省劳模的慰问金竟是三张百元假钞">送给省劳模的慰问金竟是三张百元假钞</a> <a class="btn btn-default" href="/article/407246" title="歌唱发声的基础">歌唱发声的基础</a> <a class="btn btn-default" href="/article/407247" title="歌唱基础">歌唱基础</a> <a class="btn btn-default" href="/article/407248" title="男人是怎么聊女人的(超级搞)">男人是怎么聊女人的(超级搞)</a> <a class="btn btn-default" href="/article/407249" title="世界顶级模特走秀指定背景音乐精">世界顶级模特走秀指定背景音乐精</a> <a class="btn btn-default" href="/article/407250" title="那是贯穿生命的缘分">那是贯穿生命的缘分</a> <a class="btn btn-default" href="/article/407251" title="邓玉娇涉嫌故意杀人被立案">邓玉娇涉嫌故意杀人被立案</a> <a class="btn btn-default" href="/article/407252" title="轻轻音乐80首播放器">轻轻音乐80首播放器</a> <a class="btn btn-default" href="/article/407253" title="历史上可能是最全的QQ表情">历史上可能是最全的QQ表情</a> <a class="btn btn-default" href="/article/407254" title="凉拌海带丝—不可不吃的一道抗辐射的凉菜..">凉拌海带丝—不可不吃的一道抗辐射的凉菜..</a> <a class="btn btn-default" href="/article/407255" title="治帕金森氏病(震颤麻痹)秘方">治帕金森氏病(震颤麻痹)秘方</a> <a class="btn btn-default" href="/article/407256" title="保健食品可用、禁用中草药名单">保健食品可用、禁用中草药名单</a> <a class="btn btn-default" href="/article/407257" title="中国作家全集系列0">中国作家全集系列0</a> <a class="btn btn-default" href="/article/407258" title="外国作家全集系列阅读系统0">外国作家全集系列阅读系统0</a> <a class="btn btn-default" href="/article/407259" title="快速解决肌肤问题">快速解决肌肤问题</a> <a class="btn btn-default" href="/article/407260" title="晚清第一怪杰辜鸿铭">晚清第一怪杰辜鸿铭</a> <a class="btn btn-default" href="/article/407261" title="马化腾的赚钱秘诀是什么">马化腾的赚钱秘诀是什么</a> </div> </div></div> <div class="copy-right"> <p>神马文学网,客观、专业、权威的知识性互动百科全书。</p></div> </footer> </body> </html>