Home > Web Front-end > JS Tutorial > body text

JavaScript code for dynamically creating buttons_javascript tips

WBOY
Release: 2016-05-16 15:16:55
Original
1274 people have browsed it

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template