当用户选中一个复选框时,我想执行一个操作,但是我无法使其正常工作,我在做什么错呢?
因此,基本上,用户转到我的页面,在框上打勾,然后弹出警报。
if($("#home").is(":checked"))
{
alert('');
}
最佳答案
您正在寻找的被称为事件。 jQuery提供了像这样的简单事件绑定方法
$("#home").click(function() {
// this function will get executed every time the #home element is clicked (or tab-spacebar changed)
if($(this).is(":checked")) // "this" refers to the element that fired the event
{
alert('home is checked');
}
});
关于jquery - 使用jQuery选中复选框时如何执行操作?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1854156/