为了账号安全,请及时绑定邮箱和手机立即绑定

帮忙改一段JS代码

帮忙改一段JS代码

蓝山帝景 2018-12-07 09:57:23
1 <html> 2 <head> 3 </head> 4 <body> 5 <script language="javascript"> 6 function addRowToTable() { 7 var tbl = document.getElementById('tblSample'); 8 var lastRow = tbl.rows.length; 9 // if there's no header row in the table, then iteration = lastRow + 1 10 var iteration = lastRow; 11 var row = tbl.insertRow(lastRow);//添加行 12 // left cell 13 var cellLeft = row.insertCell(0); //添加列 14 var textNode = document.createTextNode(iteration); 15 cellLeft.appendChild(textNode); 16 // right cell 17 var cellRight = row.insertCell(1); 18 var el = document.createElement('input'); 19 el.type = 'text'; 20 el.name = 'txtRow' + iteration; 21 el.id = 'txtRow' + iteration; 22 el.size = 40; 23 el.onkeypress = keyPressTest; 24 cellRight.appendChild(el); 25 // select cell 26 var cellRightSel = row.insertCell(2); 27 var sel = document.createElement('select'); 28 sel.name = 'selRow' + iteration; 29 sel.options[0] = new Option('text zero', 'value0'); 30 sel.options[1] = new Option('text one', 'value1'); 31 cellRightSel.appendChild(sel); 32 } 33 function keyPressTest(e, obj) { 34 var validateChkb = document.getElementById('chkValidateOnKeyPress'); 35 if (validateChkb.checked) { 36 var displayObj = document.getElementById('spanOutput'); 37 var key; 38 if (window.event) { 39 key = window.event.keyCode; 40 } else if (e.which) { 41 key = e.which; 42 } 43 var objId; 44 if (obj != null) { 45 objId = obj.id; 46 } else { 47 objId = this.id; 48 } 49 displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key); 50 } 51 } 52 function removeRowFromTable() { 53 var tbl = document.getElementById('tblSample'); 54 var lastRow = tbl.rows.length; 55 if (lastRow > 2) 56 tbl.deleteRow(lastRow - 1); 57 } 58 function openInNewWindow(frm) { 59 // open a blank window 60 var aWindow = window 61 .open('', 'TableAddRowNewWindow', 62 'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400'); 63 // set the target to the blank window 64 frm.target = 'TableAddRowNewWindow'; 65 // submit 66 frm.submit(); 67 } 68 function validateRow(frm) { 69 var chkb = document.getElementById('chkValidate'); 70 if (chkb.checked) { 71 var tbl = document.getElementById('tblSample'); 72 var lastRow = tbl.rows.length - 1; 73 var i; 74 for (i = 1; i <= lastRow; i++) { 75 var aRow = document.getElementById('txtRow' + i); 76 if (aRow.value.length <= 0) { 77 alert('Row ' + i + ' is empty'); 78 return; 79 } 80 } 81 } 82 openInNewWindow(frm); 83 } 84 </script> 85 <form method="get" action=""> 86 <p> 87 <input type="button" value="添加" onclick="addRowToTable();" /> 88 <input type="button" value="删除" onclick="removeRowFromTable();" /> 89 <input type="button" value="提交" onclick="validateRow(this.form);" /> 90 <input type="checkbox" id="chkValidate" /> Validate Submit 91 </p> 92 <table border="1" id="tblSample"> 93 <tr> 94 <th colspan="3">添加选项</th> 95 </tr> 96 <tr> 97 <td>1</td> 98 <td><input type="text" name="txtRow1" id="txtRow1" size="40" /></td> 99 <td> 100 <select name="selRow0"> 101 <option value="value0">text zero</option> 102 <option value="value1">text one</option> 103 </select></td> 104 </tr> 105 </table> 106 </body> 107 </html>改成可以增加试题的表单,第一行题干,第二行ABCD选项,第三行正确答案;对这块不是很明白,又比较急只能求各位大神帮忙了,谢谢了
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 419 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信