Home  >  Article  >  Web Front-end  >  JavaScript code for dynamically creating buttons_javascript tips

JavaScript code for dynamically creating buttons_javascript tips

WBOY
WBOYOriginal
2016-05-16 15:16:551275browse

Without further ado, I will just post the js code for you. The specific code is as follows:

<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Document</title>
<script type="text/javascript">
var i = 0;
function addInput(){
var o = 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>
<body onload="addInput()">
</body>
</html>

The above is the JavaScript code for dynamically creating buttons introduced by the editor. I hope it will be helpful to you.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn