首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

怎么用appendChild()方法添加表单

2012-02-03 
如何用appendChild()方法添加表单如何用appendChild()方法添加表单,如,我想在 pid p1 /p 中加入一

如何用appendChild()方法添加表单
如何用appendChild()方法添加表单,如,我想在 <p   id= "p1 "> &nbsp; </p> 中加入
一个含有事件的按扭 <input   type= "button "   value= "myButton "   id= "btn1 "   name= "btn1 "   onclick= "checkValue() ">     ????

[解决办法]
<p id= "p1 "> </p>
<script>
function clickme() {
alert(1);
}

function createInput(parentObj){
var input = document.createElement( 'input ');
input.type = 'button ';
input.value = 'myButton ';
input.id = 'btn1 ';
input.name = 'btn1 ';
input.onclick = clickme;

parentObj.appendChild(input);
}
createInput(document.getElementById( 'p1 '));
</script>
[解决办法]
var oInput = document.createElement( "input ");
with(oInput)
{
type = "button ";
value = "myButton ";
id = name = "btn1 ";
onclick = funcition(){checkValue()};
}

XXXform.appendChild(oInput);

热点排行