كما هو موضح في الصورة:
إن تنفيذ زر SELECT All هو:
نسخة الكود كما يلي:
<type type = "checkbox" name = "all" onClick = "CheckAll ()" /> حدد All <Br />
<type type = "checkbox" name = "item" value = "3000" /> الكمبيوتر المحمول: 3000 يوان <br />
<type type = "checkbox" name = "item" value = "3000" /> الكمبيوتر المحمول: 3000 يوان <br />
<type type = "checkbox" name = "item" value = "3000" /> الكمبيوتر المحمول: 3000 يوان <br />
<type type = "checkbox" name = "item" value = "3000" /> الكمبيوتر المحمول: 3000 يوان <br />
<type type = "checkbox" name = "item" value = "3000" /> الكمبيوتر المحمول: 3000 يوان <br />
<type type = "checkbox" name = "item" value = "3000" /> الكمبيوتر المحمول: 3000 يوان <br />
<type type = "checkbox" name = "item" value = "3000" /> الكمبيوتر المحمول: 3000 يوان <br />
<type type = "checkbox" name = "item" value = "3000" /> الكمبيوتر المحمول: 3000 يوان <br />
<type type = "checkbox" name = "item" value = "3000" /> الكمبيوتر المحمول: 3000 يوان <br />
<type type = "checkbox" name = "item" value = "3000" /> الكمبيوتر المحمول: 3000 يوان <br />
<type type = "checkbox" name = "all" onClick = "CheckAll ()" /> حدد All <Br />
<type type = "button" value = "احصل على المبلغ الإجمالي" onClick = "getSum ()" />
<span id = "sum"> </span>
يتم استخدام علامة الفترة الأخيرة لتخزين المنطقة التي تعرض المبلغ الإجمالي.
الكود الذي ينفذ وظيفتين "SELECT All" هو:
نسخة الكود كما يلي:
وظيفة checkall ()
{
// var allnode = document.getElementSbyName ("all") [0] ؛
// احصل على العنصر الذي تم النقر عليه
var allnode = event.srcelement ؛
var item = document.getElementSbyName ("item") ؛
لـ (var x = 0 ؛ x <item.length ؛ x ++)
{
البند [x] .cked = allnode.checked ؛
}
}
Event.Srcelement ينفذ الاستحواذ على زر الحدث الاستجابة.
يعدل For Loop الخاصية التي تم فحصها لكل مربع متعدد الفحص.
طريقة حساب المبلغ الإجمالي هي:
نسخة الكود كما يلي:
وظيفة getSum ()
{
var item = document.getElementSbyName ("item") ؛
var sum = 0 ؛
لـ (var x = 0 ؛ x <item.length ؛ x ++)
{
إذا (البند [x]. التحقق)
{
sum+= parseint (البند [x] .value) ؛
}
}
var spannode = document.getElementById ("sum") ؛
spannode.innerhtml = (sum+"meta"). fontsize (7) ؛
}
يضيف قيم القيمة لجميع خانات الاختيار المحددة.