在我的SelectAll复选框上单击触发器应该适用于所有输入 - 其上有点击事件。选择带触发器的所有复选框 - jquery
触发器工作在selectall上,但取消选中selectall不工作。它didnt全部取消输入
<input type="checkbox" id="SelectAll" />
<input class="checkBoxClass" name="pid[]" id="pid_1" value="1" onclick="javascript: total_select(1,0.35,2700.00);" type="checkbox">
<input class="checkBoxClass" name="pid[]" id="pid_2" value="2" onclick="javascript: total_select(2,0.35,2700.00);" type="checkbox">
<input class="checkBoxClass" name="pid[]" id="pid_3" value="3" onclick="javascript: total_select(3,0.35,2700.00);" type="checkbox">
下面我所做过
$(document).ready(function() {
$("#SelectAll").click(function() {
$(".checkBoxClass").attr('checked', $(this).attr('checked'));
$(".checkBoxClass").change(function(){
if (!$(this).attr("checked")){
$("#SelectAll").attr("checked",false);
}
});
});
});
以上Jquery的工作全选/ UN-选择所有复选框 - 如果我删除以下触发器,它的工作原理
$(document).ready(function() {
$("#SelectAll").click(function(){
$(".checkBoxClass").trigger("click");
$(".checkBoxClass").attr('checked', true); // if i remove this line then selectall for checkbox don't works
});
});
但我需要以上jQuery才能触发 - total_select函数
function total_select(id,carat,price){
var lenChkBox = $("input[name='pid[]']:checked").length;
if(document.getElementById("pid_"+id).checked==true) {
total_select.s++;
document.getElementById("noofs").innerHTML=total_select.s;
total_select.c +=carat;
var cs = (total_select.c).toFixed(2);
document.getElementById("carat").innerHTML=cs;
total_select.p +=price * carat;
avg_price_per = total_select.p/total_select.c;
var ca = (avg_price_per).toFixed(2);
document.getElementById("price").innerHTML="$"+ca;
} else {
total_select.s--;
document.getElementById("noofs").innerHTML=total_select.s;
total_select.c -=carat;
cs = (total_select.c).toFixed(2);
document.getElementById("carat").innerHTML=cs;
total_select.p -=price * carat;
avg_price_per = total_select.p/total_select.c;
var ca = (avg_price_per).toFixed(2);
document.getElementById("price").innerHTML="$"+ca;
}
我试过很多:
$(".checkBoxClass").attr('checked', true).triggerHandler('click');
$(".checkBoxClass").prop('checked', true).triggerHandler('click');
,但仍无法正常工作,它不检查“全选”所有的输入,并触发total_select功能与正确的结果,但是当我做不选上“全选” /取消我的输入无法取消选择/取消选中
取消选中 - 选择 - 价值应该是没有或空白的功能 – user3209031
我不明白你的意思 –
我不能把total_select()逻辑那里作为其他一些复选框ID使用...因此,我不能重复相同的功能在2位......其次我不能调用具有三个值的数据... data-a =“1”data-b =“0.35”data-c =“2700.00”,因为这里的data-b和data-c是2不同的列值和数据-a是主要的主编号 – user3209031