สอบถามการเขียน script นับการ checket หน่อยครับ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถามการเขียน script นับการ checket หน่อยครับ
สอบถามการเขียน script นับการ checket หน่อยครับ
จากตัว script เมื่อทำการกด checkbox ก็จะมีการนับจำนวนการ check ไว้ เเต่มันจะเป็นการนับรวมจำนวนทั้งหมด ถ้าผมต้องการเเบ่ง โดยที่ Select_all Foo ก็นับเฉพาะ Select_all Foo ส่วน .Select_all Bar ก็นับเฉพาะ .Select_all Bar ต้องเขียนอย่างไรครับ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <a title= "Filter Category" id= "general" class = "" ><i> Count the checkboxes <small class = "counter" ></small></i></a> <div id= "video-filter-container" > <div id= "general-content" class = "video-filter-content" > <ul id= "general-ul" class = "wpuf-category-checklist" > <li id= "category" > <label class = "selec" ><input type= "checkbox" class = "select_all" /> .Select_all Foo</label> <ul class = "children" > <li id= "category-4" ><label class = "selectit" ><input value= "4" type= "checkbox" name= "wpmm[]" id= "in-category-4" /> Foo1</label></li> <li id= "category-112" ><label class = "selectit" ><input value= "112" type= "checkbox" name= "wpmm[]" id= "in-category-112" /> Foo2</label></li> </ul> </li> <li id= "category" > <label class = "selec" ><input type= "checkbox" class = "select_all" /> .Select_all Bar</label> <ul class = "children" > <li id= "category-3" > <label class = "selectit" ><input value= "3" type= "checkbox" name= "wpmm[]" id= "in-category-3" /> Bar1</label></li> <li id= "category-115" ><label class = "selectit" ><input value= "115" type= "checkbox" name= "wpmm[]" id= "in-category-115" /> Bar2</label></li> <li id= "category-114" ><label class = "selectit" ><input value= "114" type= "checkbox" name= "wpmm[]" id= "in-category-114" /> Bar3</label></li> </ul> </li> </ul> </div> </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | $( function () { $( '#general i .counter' ).text( ' ' ); var generallen = $( "#general-content input[name='wpmm[]']:checked" ).length; if (generallen>0){$( "#general i .counter" ).text( '(' +generallen+ ')' );} else {$( "#general i .counter" ).text( ' ' );} }) function updateCounter() { var len = $( "#general-content input[name='wpmm[]']:checked" ).length; if (len>0){$( "#general i .counter" ).text( '(' +len+ ')' );} else {$( "#general i .counter" ).text( ' ' );} } $( "#general-content input:checkbox" ).on( "change" , function () { updateCounter(); }); $( function () { $( '.select_all' ).change( function () { var checkthis = $( this ); var checkboxes = $( this ).parent().next( 'ul' ).find( "input[name='wpmm[]']" ); if (checkthis.is( ':checked' )) { checkboxes.attr( 'checked' , true ); } else { checkboxes.attr( 'checked' , false ); } updateCounter(); }); }) |

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
แยก checkbox ใส่ css class จัดกลุ่ม
1 2 | <input class = "bar" type= "checkbox" ../> <input class = "foo" type= "checkbox" ../> |
นับจำนวน
1 2 | $( ".foo:checked" ).length $( ".bar:checked" ).length |

ขอบคุณทุกการสนับสนุน
![]()