2013-08-31 59 views
0

我正在嘗試監視收音機組上的更改。單選按鈕檢查屬性不更新用戶操作

我使用面漆,具有以下HTML:

<ul class="topcoat-list"> 
    <li class="topcoat-list__item"> 
     <label class="topcoat-radio-button__label"> 
      <input type="radio" name="topcoat" value="1" checked="checked"> 
      <div class="topcoat-radio-button"></div> 
      Test1 
     </label> 
    </li> 
    <li class="topcoat-list__item"> 
     <label class="topcoat-radio-button__label"> 
      <input type="radio" name="topcoat" value="2"> 
      <div class="topcoat-radio-button"></div> 
      Test2 
     </label> 
    </li> 
    <li class="topcoat-list__item"> 
     <label class="topcoat-radio-button__label"> 
      <input type="radio" name="topcoat" value="3"> 
      <div class="topcoat-radio-button"></div> 
      Test3 
     </label> 
    </li> 
</ul> 

對於原因,我不完全得到的checked屬性的時候使用選擇另一個單選按鈕沒有更新......

我想能夠監測與JavaScript的變化,但現在,我不能得到無線電集團的價值...

$('input[name=topcoat]').change(function(){ changed() }); 

function changed() { 
    id = $('input[name=topcoat]').val(); 
    alert(id); 
} 
+0

當你選中一個複選框,它是被更新不是屬性 –

+2

你可以使用'$(輸入所選擇的項目'[NAME =‘面漆’]屬性:checked')。val()' –

+0

@ArunPJohny,你的評論解決了我的問題。我將答案標記爲已接受(我不知道你們中的哪一位是第一位)。 –

回答

1

請嘗試這種方式迪希望這本書能解決你的問題:

<script type="text/javascript"> 
$(function(){ 

$('input[name="topcoat"]').change(function(){ changed() }); 

function changed() { 
    id = $('input[name="topcoat"]:checked').val(); 
    alert(id); 
} 

}); 

</script>