今天有朋友问到,如何实现,通过一个select或者input的值来设置表单的数量,我写了如下代码基本能实现功能,javascript代码如下:
function insert(x) {
var html = "";
var i;
for(i=1;i< =x;i++) {
html = html + "<tr><td>a" + i + "</td><td>";
html = html + "<input name=\"a" + i + "\" type=\"text\" id=\"a" + i + "\" />";
html = html + "</td>";
}
html = "<table border=\"1\">" + html + "</table>";
document.getElementById("tablecontent").innerHTML = html;
}
function cg(obj) {
insert(obj.value);
}
在HTML中调用如下:
<form action="" method="post" name="form1" id="form1">
<select name="totalnum" id="totalnum" onchange="javascript:cg(this);">
<option value="10">10</option>
<option value="2">2</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
<div id="tablecontent"></div>
</form>
function insert(x) {
var html = "";
var i;
for(i=1;i< =x;i++) {
html = html + "<tr><td>a" + i + "</td><td>";
html = html + "<input name=\"a" + i + "\" type=\"text\" id=\"a" + i + "\" />";
html = html + "</td>";
}
html = "<table border=\"1\">" + html + "</table>";
document.getElementById("tablecontent").innerHTML = html;
}
function cg(obj) {
insert(obj.value);
}
在HTML中调用如下:
<form action="" method="post" name="form1" id="form1">
<select name="totalnum" id="totalnum" onchange="javascript:cg(this);">
<option value="10">10</option>
<option value="2">2</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
<div id="tablecontent"></div>
</form>
看网上报道山寨电影《笑闹天宫之妖怪都市雷人》听说搞笑,专门下了来看,看到一半发现了一个朋友在里面我汗!结果半天原来是游戏笑闹天宫的广告片。
Recent Comments