如何在html中的checkbox判断是否被选中

如何在html中的checkbox判断是否被选中,第1张

很简单去看代码中的是否有

checked="checked"

这个属性。

如果有,说明这个checkbox已经被选中,如果为空则未被选中。

举个例子如下

<input

type="checkbox"

name="sample"

id="sample"

checked="checked">

<input type="checkbox" id="checkbox1" />

<script>

$(document).ready(function(){

if($("#checkbox1").attr("checked")==true)

{

alert("checkbox已选中")

}

})

</script>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6115677.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-15
下一篇 2023-03-15

发表评论

登录后才能评论

评论列表(0条)

保存