Jquery onchange event for switch now instantly

I try to make the identifier active only when a certain type of switch is selected. The following is jQuery code:

$(document).ready(function() {
   $('#Type').attr('disabled', 'disabled');
   $('input[@name=action]').change(function() {
     if ($("input[@name=action]:checked").val() == 'SomeKind')              
        $('#Type').removeAttr('disabled');
     else 
        $('#Type').attr('disabled', 'disabled');
    });
});

This works as intended, but with one drawback. When I click on the switch SomeKind, it does not make it Typeactive instantly; instead, I have to click again (anywhere on the page) for it to Typebe active.

I'm on IE7

+3
source share
2 answers

if the action is the name of your flag, then use the click event instead of changing it,

$('input[@name=action]').click(function() {
     if (this.checked && $(this).val() == 'SomeKind')              
        $('#Type').removeAttr('disabled');
     else 
        $('#Type').attr('disabled', 'disabled');
});
+1
source

IE7 , , . :

http://norman.walsh.name/2009/03/24/jQueryIE

Chinmayee .click ( , , , ), , :

$(':radio').click(function() {
    try {
        this.blur();
        this.focus();
    }
    catch (e) {}
});

kludge IE7, , , (kludge kludge). , IE8 .

+3

Source: https://habr.com/ru/post/1777604/


All Articles