开发者

Issue with rules overlapping

I have 2 checkbox rules that are overlapping. This one runs first

$("#BMFNP").change(function() {
    if($(this).is(":checked") && $("#INTEF").is("开发者_StackOverflow中文版:not(:checked)")) {
        $("#INTEF").attr("checked", true);
        alert("foo");
    } 
});

This one runs second:

$("#BMFNP").change(function() {
    if($(this).is(":checked") && $("#INTEF").is(":checked")) {
    alert("bar");
    }
});

So basically the first one runs if BMFNP is checked, and INTEF isn't it checks INTEF and runs the alert. At that time, both are checked so it runs the second function. How can I fix this? I need both to work and display different messages for each situation, if BMFNP is checked, INTEF isn't check INTEF and alert it has been added and BMFNP can only do xxxxx. If both are checked, simply alert that BMFNP can only do xxxx, no need to alert it has been added.

Thanks,


$("#BMFNP").change(function() {
    if($(this).is(":checked") {
       if( $("#INTEF").is(":checked")) {               
            alert("bar");
       } else {
            $("#INTEF").attr("checked", true);
            alert("foo");
       }
    } 
});

like that?


You can use a single event handler, and significantly shorten the solution:

$("#BMFNP").change(function() {
    if(this.checked) {
        $("#INTEF").is(":checked") ? alert('bar') : alert('foo');
    }
});


The comments are difficult to format code in. This does exactly what has been asked for.

$("#BMFNP").change(function() {
  if($(this).is(":checked")) {
        if($("#INTEF").is(":checked")) {
              alert("only outside brazil");
        } else { $("#INTEF").attr("checked", true);
            alert("INTEF has been added and only avail. outside brazil");
            }
    }
});

@karim79 - yours is shorter, but only runs the alerts, I need to add checked to INTEF if it isn't and BMFNP is like above. Thanks for all your help guys!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜