我有一個無線電輸入,並在頁面上的其他位置的按鈕上,我檢查是否檢查,並將選中的值更改爲打開或關閉。爲什麼這不簡單,如果:檢查輸入正常工作?
輸入的樣子:
<input type="radio" name="send" value="1" checked="true" />
或者
<input type="radio" name="send" value="1" />
我有相當簡單的jQuery做檢查:
$input = $('input[name=send]');
if($input.is(":checked"))
{
$input.attr("checked", false);
}
else
{
$input.attr("checked", true);
}
的問題是,如果在頁面加載和輸入被檢查,出於某種原因,我需要點擊按鈕兩次,才能識別狀態的其他部分NT。
如果頁面從輸入未選中開始,那麼在第一次單擊該按鈕時,按預期工作。然後每次點擊都可以工作。但是,如果輸入被檢查,則不是初始加載。
標記輸入爲正確的方式是什麼?
如何在輸入[type = radio]上完成正確的if/else語句來查看它是否被檢查?
'$ input.prop('checked',!$ input [0] .checked);'? 或更好'$ input [0] .checked =!$ input [0] .checked'。 – Jashwant