2015-11-20 97 views
0

原諒我的無知,但我只是在學習。我爲複選框選擇使用特定的JavaScript模板。 Found here強制特定複選框選擇

我想強制一個特定的複選框選擇,這意味着無論用戶選擇什麼,一個特定的複選框是總是選中的框。我已經嘗試了一些東西,沒有找到任何運氣。任何幫助表示讚賞,謝謝!

<form class="ac-custom ac-radio ac-circle" autocomplete="off"> 
       <h2>Question</h2> 
       <ul> 
        <li><input id="r5" name="r2" type="radio"><label for="r5">Selection 1</label></li> 
        <li><input id="r6" name="r2" type="radio"><label for="r6">Selection 2</label></li> 
        <li><input id="r7" name="r2" type="radio"><label for="r7">Selection 3</label></li> 
        <li><input id="r8" name="r2" type="radio"><label for="r8">Selection 4</label></li> 
       </ul> 
      </form> 
+0

請顯示您的代碼 – WillardSolutions

+0

對不起,剛添加它!謝謝 – Matt

回答

0

您可以使用所有複選框的事件更改。當觸發事件更改時,請使用javascript或jquery檢查您的目標複選框。

+0

注意複選框和收音機是一樣的。 –

0

試了一下的jQuery:

$("input[type='radio']").on('change', function(e) { 

    // Prevent the default action 
    e.preventDefault(); 

    $('#r5').prop("checked", true); 

}); 

http://jsfiddle.net/9s0gzxq3/

只需更改#R5到要檢查單選按鈕的ID。

+0

完美。謝謝!!! – Matt