2017-02-10 69 views
-3

我想選擇一個單選按鈕離開這裏使用Javascript兩個單選按鈕來選擇是我的HTML代碼,我有只有一個單選按鈕必須一次

<div class="row"> 
    <div class="form-group"> 
     <label class="control-label col-sm-6">Feel Of The Cards : </label> 
     <div class="col-sm-6"> 
      <input type="radio" value="NonEmbossed" name="feel_of_card" /> Non Embossed/Smooth Finished<br> 
      <input type="radio" value="Embossed" name="feel_of_card1" /> Embossed/Linen Finished/Textured Cards 
     </div> 
    </div> 
</div> 

我想打一個單獨的函數中從兩個單選按鈕中選擇一個單選按鈕?

什麼是寫javascript功能的可能方法?

+1

http://stackoverflow.com/questions/9476617/how-to-set-radio-button-status-with-javascript –

+1

的重複[如何使用JavaScript設置單選按鈕狀態](http:/ /stackoverflow.com/questions/9476617/how-to-set-radio-button-status-with-javascript) –

+0

來吧人先學習基本知識,做研究,然後張貼問題 –

回答

1

你不需要JavaScript來做到這一點。只要給同一name到的兩個複選框

<div class="row"> 
 
    <div class="form-group"> 
 
    <label class="control-label col-sm-6">Feel Of The Cards : </label> 
 
    <div class="col-sm-6"> 
 
     <input type="radio" value="NonEmbossed" name="feel_of_card" /> 
 
     Non Embossed/Smooth Finished<br /> 
 
     <input type="radio" value="Embossed" name="feel_of_card" /> 
 
     Embossed/Linen Finished/Textured Cards 
 
    </div> 
 
    </div> 
 
</div>

1
<div class="row"> 
         <div class="form-group"> 
         <label class="control-label col-sm-6">Feel Of The Cards : </label> 
         <div class="col-sm-6"> 
         <input id="_1234" type="radio" value="NonEmbossed" name="feel_of_card" /> Non Embossed/Smooth Finished<br> 
         <input id="_1235" type="radio" value="Embossed" name="feel_of_card" /> Embossed/Linen Finished/Textured Cards</div> 
         </div> 
         </div> 

爲什麼你使用的所有替代值id? 也不要混合CSS語法(#用於標識符)與本機JS 原生JS解決方案:

document.getElementById(「_ 1234」)。checked = true;

JQuery的解決方案:

$( 「#_ 1234」)丙( 「選中」,真正的);

相關問題