最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can't cancel the onchange event for my HTML checkbox - Stack Overflow

programmeradmin0浏览0评论

I have a working example of this but I'm not sure why my implementation isn't working. Can somebody please help? I'm missing something and I need another set of eyes to find it for me. :)

JSFiddle demo <-- see code here.

I'm trying to reproduce the functionality used here. I seem to be a little confused about passing/accessing the event variable around.

Thanks!! :-)

I have a working example of this but I'm not sure why my implementation isn't working. Can somebody please help? I'm missing something and I need another set of eyes to find it for me. :)

JSFiddle demo <-- see code here.

I'm trying to reproduce the functionality used here. I seem to be a little confused about passing/accessing the event variable around.

Thanks!! :-)

Share Improve this question asked Nov 12, 2012 at 15:41 JaxidianJaxidian 13.5k9 gold badges87 silver badges131 bronze badges 1
  • changing onChange to onClick works for me.. strange – Atif Commented Nov 12, 2012 at 15:45
Add a ment  | 

3 Answers 3

Reset to default 5

Bind to the Click event: example

$(document).ready(function() {
    $('#checkbox1').click(function(event) {
        if (flag) {
            CancelEvent(event);
            return event.returnValue;
        }
        SomeOtherStuff('this method has real functionality too');
    });
});​

Change is a little to late in the event structure to cancel the action that already happened. In addition, the return value was being omitted. So I added it to the event handler.

Working jsfiddle.

return false on checkbox click.

$('#checkbox1').click(function(event) {

    return false;
});

you can either use disabled attribute of input

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

You forgot to add return event.returnValue; and onClick will work instead of onChange?

http://jsfiddle/wanUF/11/

发布评论

评论列表(0)

  1. 暂无评论