开发者

How to find checked event in a checkbox using jquery?

开发者 https://www.devze.com 2023-03-04 05:42 出处:网络
I am trying to execute a function on clicking a check box. For that I am using the following code but it is not working can anyone find whats the problem with this code?

I am trying to execute a function on clicking a check box. For that I am using the following code but it is not working can anyone find whats the problem with this code?

$('#selectAll').click(function(){
     alert("hi");
});

HTML

<th><i开发者_高级运维nput type="checkbox" name="selectl" value="ON" id="selectAll"/></th>


I tried this example below and it is working with the latest jquery version.

    <script type="text/javascript">
    $(document).ready(function () {
        $("#chk").change(function () {
            var $this = $(this);
            var checked = $this.is(':checked');
            if (checked) {
                alert('checked');
            }
        });
    });
</script>
<input id="chk" type="checkbox" />


$(function(){
    $('#selectAll').change(function(){ 
        alert("value changed");
    });
});

See a working demo.


$('#selectAll').bind('change',function(){ 
    alert("hi");
});

Use 'change' instead! jsFiddle

0

精彩评论

暂无评论...
验证码 换一张
取 消