我嘗試使用以下功能切換我的radio
按鈕true
或false
。單選按鈕啓用/禁用不按預期方式工作
但作爲第一次點擊,我沒有得到任何迴應。後來它工作正常。要解決這個問題,這裏有什麼問題?
var switching = false;
$('button').on("click", function() {
switching = switching == false ? switching = true : switching = false;
console.log("switching", switching); //first click true but not works!
$(":radio").attr("disabled", switching);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" name="foo" value="Y" checked disabled>
<input type="radio" name="foo" value="N" disabled>
<input type="radio" name="foo" value="X" disabled>
<button>
Switch Me
</button>
更新小提琴的JS - http://jsfiddle.net/qqVGu/ 592/ – Pugazh