简单的jQuery函数在某些浏览器中不起作用

时间:2015-08-04 14:42:55

标签: javascript jquery html

我正在构建一个用户必须同意条款和条件的网站。滚动到框的末尾后,启用该复选框。这是代码:

<script type="text/javascript">
    $(function() {
        $('#rules_box').scroll(function () {
            if ($(this).scrollTop() >= $(this)[0].scrollHeight - $(this).height() - 15 ) {
             $('#iagree').removeAttr('disabled');
            }
         });
    });
</script>

这适用于大多数浏览器。但有些人拒绝工作。即使我只是

$('#iagree').removeAttr('disabled');

本身没有滚动条件。这个页面正在运行许多正在运行的javascripts。

有人说它没有在他们的手机上工作,有人说虽然它在我的Firefox上工作但它并没有在Firefox上工作。

jQuery是不是很挑剔?这是否意味着我必须以另一种方式做到这一点?

修改 你很快就会被标记为傻瓜,但这个问题还没有得到解答。 问题在相同的选择浏览器中仍然存在,请参阅更新的代码

    $(function() {
        $('#rules_box').scroll(function () {
            alert('something');
            $('#iagree').prop("disabled", false); 
         });
    });

不会触发警报或更改复选框状态

3 个答案:

答案 0 :(得分:0)

对于复选框元素,您应使用.removeProp()代替.removeAttr()

$('#iagree').removeProp('disabled');

另请参阅:https://api.jquery.com/removeAttr/https://api.jquery.com/attr/

答案 1 :(得分:0)

请使用

$('#iagree').prop("disabled", false); 

答案 2 :(得分:0)

使用.prop('disabled',false)代替removeAttr('disabled')

related question

相关问题