نسخة الكود كما يلي:
</pre> <pre name = "code"> <html>
<body>
<type type = "button" name = "input []" value = "button1" /> <br />
<type type = "button" name = "input []" value = "button2" /> <br />
<type type = "button" name = "input []" value = "button 3" /> <br />
<div id = "add"> </viv>
</body>
</html>
<script type = "text/javaScript">
// احصل على جميع أدوات التحكم في الإدخال من خلال getElementsByTagname
var inputs = document.getElementSbyTagName ("input") ؛
// ربط حدث OnClick للزر 0 ، تنبيه
المدخلات [0] .onclick = function () {
تنبيه ("سأختبره") ؛
}
// ربط حدث OnClick لكل زر ، تنبيه
لـ (var i = 0 ؛ i <inputs.length ؛ i ++) {
المدخلات [i] .onclick = function () {
تنبيه ("سأختبره") ؛
}
}
window.onload = function () {
// تحديد صفيف arrrs
var arrrs = new array () ؛
// إضافة حلقة
لـ (var i = 0 ؛ i <2 ؛ i ++) {
// أضف نوعين من الإدخال = "زر" value = "جديد" +i
var input = document.createElement ("input") ؛
input.type = "button" ؛
input.value = "add" + i ؛
// تذكر وضع المدخلات التي تم إنشاؤها في ARRRS
arrrs.push (المدخلات) ؛
// ثم ضع الإدخال في div مع id = "إضافة"
document.getElementById ("add"). appendChild (input) ؛
}
// استخدم أيضًا [0]
arrrs [0] .onclick = function () {
تنبيه ("سأختبره مرة أخرى") ؛
}
}
</script>