2013-09-27 60 views
0

。 。我無法找到一個按鈕的onclick函數的正確答案,禁用三個複選框。 。 。Onclick按鈕禁用複選框

<input id="option" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/> 
<input id="option" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/> 
<input id="option" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/> 

而添加onclick函數的按鈕已經有很多onclick函數。

<input type="button" class="button2" id="item2" value="Add to Cart" Title="Add to Cart" onClick="addItem_check('item_listing_100','ItemTable','100','Amul Butter','500','g','150.00','1','kg','200.00','2','kg','250.00'); amul1.style.backgroundColor='#c2ed5c'; if(this.value=='Add to Cart') {this.value = 'Remove from Cart'}; item2();"/> 

所以,請給我一個解決方案傢伙

+3

** id **必須是唯一的。函數addItem_check和item2是做什麼的? –

+0

Rohan addItem_check將項目添加到購物車,而item2我正在使用複選框禁用功能。 。到目前爲止不太好 – Zain

+0

「onclick =」this.checked =!this.checked「」對於任何事情都有幫助? – mavrosxristoforos

回答

1

與你正在嘗試做的問題是你擁有了所有三個複選框相同id="option"。他們需要是獨一無二的。

你可以做到以下幾點:

<input id="option1" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/> 
<input id="option2" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/> 
<input id="option3" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/> 

在Javascript中:

$(function(){ 
    $('#button1').click(function(){ 
     for(var i=1;i<=3;i++) 
      $('#option'+i).prop('disabled', true); 
    }); 
}); 
0

你可以做這樣的:

$(function(){ 
     $('#button1').click(function(){ 
     $('input[type=checkbox]').attr('disabled','true'); 
     }); 
    }); 
+0

您必須使用** prop()**而不是** attr()** –

0

試試這個,

$(function(){ 
     $('#button1').click(function(){ 
     $('.ckbox').prop('disabled','true'); 
     }); 
    }); 
+0

您必須使用** prop()**而不是** attr()** –

+0

@RohanKumar:謝謝。 – Jaimin

0

試試這個通過點擊按鈕來禁用複選框。

'item2'是按鈕的ID &根據您的示例,'ckbox'是複選框的類。

jQuery(function($) { 
    $("#item2").click(function(){ 
     $(".ckbox").attr("disabled","disabled"); 
    }); 
}); 
相關問題