在我的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