jQuery 检查输入是否为类型复选框?
2022-08-30 02:28:44
我想找出输入是否是复选框,但以下内容不起作用:
$("#myinput").attr('checked') === undefined
再次感谢!
我想找出输入是否是复选框,但以下内容不起作用:
$("#myinput").attr('checked') === undefined
再次感谢!
您可以使用伪选择器调用 jQuery 的函数::checkbox
is
$('#myinput').is(':checkbox')
>>> a=$("#communitymode")[0]
<input id="communitymode" type="checkbox" name="communitymode">
>>> a.type
"checkbox"
或者,更多的jQuery风格:
$("#myinput").attr('type') == 'checkbox'