动态创建按钮的JavaScript代码
废话不多说了,直接给大家贴js代码了,具体代码如下所示:
<!doctypehtml>
<html>
<head>
<metacharset="UTF-8"/>
<title>Document</title>
<scripttype="text/javascript">
vari=0;
functionaddInput(){
varo=document.createElement('input');
o.type='button';
o.value='按钮'+i++;
if(o.attachEvent){
o.attachEvent('onclick',addInput)
}else{
o.addEventListener('click',addInput)
}
document.body.appendChild(o);
o=null;
}
</script>
</head>
<bodyonload="addInput()">
</body>
</html>
以上所述是小编给大家介绍的动态创建按钮的JavaScript代码,希望对大家有所帮助。