2017-03-06 125 views
0

我有一個頁面樣本數jQuery的標籤......如何禁用時,選中複選框

Js/jquery.js 
Js/jquery-2.js 
Js/jquery-3.js 

由於墜毀彼此在同一時間,將無法正常工作使用所有這些的.js標籤相同的時間。

我創建了3個複選框,這樣的...

<input name="jquery" type="checkbox" value="jquery"> 
<input name="jquery-2" type="checkbox" value="jquery-2"> 
<input name="jquery-3" type="checkbox" value="jquery-3"> 

檢查時,其中任何複選框,併成爲禁用,所以對於樣本...我喜歡什麼。我檢查了jquery和jquery-2,並取消了jquery-3的檢查。

我的問題是,如何編寫代碼禁用從文件檢查時的jquery。

非常感謝。

+0

你不能簡單地禁用加載後的庫,而只是像刪除其參考: 'jQuery = {}'。你可能想考慮使用MVC框架。 –

回答

0

假設你想要的複選框來一組(選擇1取消選中所有其他),你可以這樣做的行爲:

let checkBoxes = $("[name^=jquery]") 

// Listen to changes on all checkBoxes, ignore the current element and uncheck all else 
// Make sure to use jQuery 1.6+ 
checkBoxes.change(function(e) { 
    const me = this; 
    checkBoxes.not(me).prop('checked', false).removeAttr('checked') 
})