簡體   English   中英

跟蹤取消選擇電台

[英]Tracking deselecting radio

有沒有一種方法可以跟蹤何時取消選擇無線電元素?

<script type="text/javascript">
$().ready(function() {
    $('#answer-1').change(function(){
        console.log('radio-1 changed');
    });

    $('#answer-2').change(function(){
        console.log('radio-2 changed');
    });

});
</script> 

<input name="question-1" type="radio" id="answer-1" />Value
<input name="question-1" type="radio" id="answer-2" />Value

JSFiddle鏈接

預期結果:選擇答案1時,顯示事件“無線電1已更改”,然后切換到答案2時, 顯示無線電2已更改且無線電1已更改

實際結果:選擇答案1時,顯示事件“無線電1更改”,然后切換到答案2時,僅顯示“無線電2更改”

當無線電被取消選擇時,有沒有辦法獲取事件?

你可以使用.data

這是可能有助於http://jsfiddle.net/wZ73z/19/的小提琴

嘗試這個

<script type="text/javascript">
$().ready(function() {
    $('input[name=question-1]').change(function(){
        if(this.checked)
          console.log('radio is selected');
        else
          console.log('radio is note selected');
    });
});
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM