简体   繁体   English

复选框中的onclick在IE中不起作用

[英]onclick in a checkbox doesn't work in IE

I make an event handler onclick and IE 9,8,7 event starts work only when I turn on the console when I turn it off will work too. 我使事件处理程序onclick和IE 9,8,7事件启动仅在我打开控制台时才起作用,而在关闭它时也将起作用。 How can I solve this problem? 我怎么解决这个问题? Thank you! 谢谢! There is my code: 有我的代码:

function changeCheck(id) // onClick функция акт/деакт. checkbox
{
    //checkbox = $('span#'+id).children().eq(0); // получаем checkbox в объект
    checkbox = $('span#'+id).children().eq(0); // получаем checkbox в объект
    console.log(checkbox);
    if(checkbox.attr('rel') !='nosumm') 
    {
        var totalSum = parseInt($('div#stoim').children().text()); // получаем начальную стоимость        
        if(!checkbox.attr('value').length) // если кликнули по "платежным системам" 
        {
            if((checkbox).is(':checked') == false) // если еще не отмечено, то отмечаем
            {
                checkbox.checked=true;
                $('span#'+id).css('background-position','0 -22px');
                if(checkbox.attr('checked','checked'))
                {
                    $('div#type_plati').slideDown();
                }
            }
            else // если checkbox отмечен
            {
                $('span#'+id).css('background-position','0 0');
        for(var key in paysystem)
        {
                    if($('input#choise'+paysystem[key]).attr('value') && $('input#choise'+paysystem[key]).is(':checked')==true)
                    {
            //console.log($('input#choise'+paysystem[key]).attr('value'));
            //console.log($('input#choise'+paysystem[key]).is(':checked'));
            totalSum = totalSum - parseInt($('input#choise'+paysystem[key]).attr('value'));         
                    }
                    $('span#niceCheckbox'+paysystem[key]).css('background-position','0 0');
                    $('span#niceCheckbox'+paysystem[key]).children().eq(0).removeAttr('checked');
                }
                $('input#subTotal').val(totalSum); // Записуем финальную цену на отправку
                $('div#stoim').children().text(totalSum);           
                if(checkbox.removeAttr('checked')) $('div#type_plati').slideUp(); 
            }        
        }
        else
        {
            if((checkbox).is(':checked') == false) // если еще не отмечено, то отмечаем
            {
                checkbox.checked=true;
                $('span#'+id).css('background-position','0 -22px');
                checkbox.attr('checked','checked');
                if(checkbox.attr('checked','checked'))
                {
                    totalSum = totalSum + parseInt($(checkbox).attr('value'));
                    $('div#stoim').children().text(totalSum);
                }
            }
            else // если checkbox отмечен
            {
                $('span#'+id).css('background-position','0 0');
                if(checkbox.removeAttr('checked'))
                {
                    totalSum = totalSum - parseInt($(checkbox).attr('value'));
                    $('div#stoim').children().text(totalSum);
                }
             } 
            $('input#subTotal').val(totalSum); // Записуем финальную цену на отправку
            $('div#stoim').children().text(totalSum);           
        }
    }
    else // обычные checkbox
    {
        if((checkbox).is(':checked') == false) // если еще не отмечено, то отмечаем
        {
            checkbox.checked=true;
            $('span#'+id).css('background-position','0 -22px');
            checkbox.attr('checked','checked');
        }
        else // если checkbox отмечен
        {
            $('span#'+id).css('background-position','0 0');
            checkbox.removeAttr('checked');
        }  
    }    

}

There is html code: 有html代码:

<li><span class="niceCheck"  onclick="changeCheck(this.id)" id="niceCheckbox2" rel=""><input type="checkbox" name="ch1" id="ch1" value="370"/> <label  for="ch1">Форма обратной связи</label></span></li>

There is a console.log(checkbox); 有一个console.log(checkbox); in your code thats not commented out. 在您的代码中,没有注释掉。
This will break the code in IE if there is no console. 如果没有控制台,这将破坏IE中的代码。

And since you're already using jQuery you might want to take a look at the .change() function/event in the documentation: http://api.jquery.com/change/ 并且由于您已经在使用jQuery,所以您可能需要查看文档中的.change()函数/事件: http : .change()
This could be what you want to use in the first place. 这可能是您首先要使用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM