Dynamically added switch is not updated when clicked on IE6, IE7

I added a dynamic switch group to the DOM using jQuery. I have registered event handlers that work well. However, when pressed in IE6 and IE7, the switch group is not updated with which the button is installed.

My source code is similar to this:

<body>
<form action="radio-ie7_submit" method="get" accept-charset="utf-8"></form>
<script type="text/javascript" charset="utf-8">
    $(function() {
        $.each(['A','B', 'C'], function (i, e) {
            $('<input>')
                .attr('type', 'radio')
                .attr('name', 'foo')
                .attr('checked', i == 1 ? 'checked' : '')
                .val(e)
                .appendTo($('form'))
                .after(e + '<br />')
                .click(function(){
                    alert('Kliiik')
                })
        })  
    })
</script>
</body>

Again, when I press the switch, the event handler is called correctly, but the switches are not updated. I made this hack that seems to work:

<body>
<form action="radio-ie7_submit" method="get" accept-charset="utf-8"></form>
<script type="text/javascript" charset="utf-8">
    $(function() {
        $.each(['A','B', 'C'], function (i, e) {
            $('<input>')
                .attr('type', 'radio')
                .attr('name', 'foo')
                .attr('checked', i == 1 ? 'checked' : '')
                .val(e)
                .appendTo($('form'))
                .after(e + '<br />')
                .click(function(){
                    $('input[name="' + this.name + '"]').each(function () { this.checked = false });
                    this.checked = true;
                    alert('Kliiik')
                })
        })  
    })
</script>
</body>

, , , , . , . ? - , , ?

.

+3
1

IE . JQuery. IE 6,

            .click(function(){
                $('input[name="' + this.name + '"]').attr('checked',''); 
                this.checked = true; 
                alert('Kliiik')                
            })
+3

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


All Articles