is it for XML or DHTML? here is an example for DHTML, it is similar in XML:<script language="javascript">
var n=1;
function addInput()
{
var input = document.createElement("INPUT");
input.type="text";
input.name="whatever"+n++;
document.form1.appendChild(input);
}
</script>
<form name="form1">
<input type="button" value="add" onclick="addInput()">
</form>
hello world
var n=1;
function addInput()
{
var input = document.createElement("INPUT");
input.type="text";
input.name="whatever"+n++;
document.form1.appendChild(input);
}
</script>
<form name="form1">
<input type="button" value="add" onclick="addInput()">
</form>
hello world
解决方案 »
- js object add index
- 为什么test方法不执行,应该怎么调用呢?
- 用XMLHTTPRequest获取网页源代码的疑问?
- extjs input 执行onclick事件的时候总是出现未定义!这是为什么的呀!
- 关于 Highcharts 制图的问题........................................................懂得请..
- 如何在父页面提交iframe中的表单?
- 请问我在筐架里弹出一个新窗口后,要关闭一个那个筐架页,应该如何做到!! 急!!!!
- ActiveXObject问题
- 给大家一个脚本,用来调试脚本的。
- 关闭窗口的问题??
- 关于 VML 的整理已经完成了。。 谢谢大家的支持!!
- 请问怎样用VML得到一个圆角的TABLE?
<option>aaa</option>
<option>bbb</option>
<option>ccc</option>
</select>
<button onclick="test.removeChild(test.firstChild)">test1</button>
<button onclick="test[0]=null">test2</button>
<select id=test size=5 style="width:50px"></select>
<button onclick="test[test.length]=new Option('test','test');">test1</button>
<button onclick="test.insertBefore(new Option('test','test'));">test2</button>
<button onclick="test.appendChild(new Option('test','test'));">test3</button>
<button onclick="test[test.length]=new Option('test','test');">test1</button>
<button onclick="test.insertBefore(new Option('test','test'));">test2</button>
<button onclick="test.appendChild(new Option('test','test'));">test3</button>
<button onclick="alert(test.outerHTML)">view</button>
但是test2和test3都不能显示所添加的项目
添加后是 <option value=test></option>
我每次遇到Select,都不得不考虑常规方法是否可行
<button onclick='test.insertBefore(document.createElement("option")).innerText="2";'>add2</button>
<button onclick='test.appendChild(document.createElement("option")).innerText="3";'>add3</button>
<button onclick="alert(test.outerHTML)">view</button><button onclick="test.removeChild(test.children[0])">del1</button>
<button onclick="test.firstChild.removeNode()">del2</button>
<button onclick="test[0]=null">del3</button>