这是我的代码:
<input type="radio" id="allIB"style="vertical-align:middle;height:10px;width:15px;top:10px;" name="selMethodCode" value="" onClick="selInterface(this.id);enableSave1(this.id)">
<input type="radio" id="allOB" style="vertical-align:middle;height:10px;width:15px;top:10px;" name="selMethodCode" value="" onClick="selInterface(this.id);enableSave1(this.id)">
function enableSave1(id)
{
abc=id;
if(document.getElementById('abc').checked)
{
alert('done');
}
}
这无法正常工作并引发错误(需要对象......)。
最佳答案
您可以将 id 参数直接传递给 getElementById() 函数,或者不使用 getElementById:
<input type="radio" id="allIB" name="selMethodCode" value="" onClick="selInterface(this);enableSave1(this)">
function selInterface(radio){
if(radio.checked){
alert("done"+radio.id)
}
关于javascript - 无法确定是否选中了单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18785192/