代码在chrome中运行良好,但在IE和Firefox中没有

时间:2013-10-06 15:10:23

标签: jquery html internet-explorer google-chrome firefox

我这里有一些代码。这在Chrome中运行良好,但在IE和Firefox中没有。

$(document).ready(function(){
    $(".thumb").click(function(){
        alert ("Reached here.");
        var cat_id = $(this).attr('id'); // get category id
        alert (cat_id);

    });
});


<a href="#" class="thumb" id = "20" name="df" >
    <img src="images/dry_fruits.png" alt="Title #0" width="75" height="75"/>
</a>

它甚至没有在Firefox和IE中发出警报。有人可以帮我确定一下这个问题。

任何帮助都将受到高度赞赏。

Devesh

2 个答案:

答案 0 :(得分:1)

它看起来像jQuery 2.0.2的一个错误。我摆弄它,IE只在$(文件).ready()上抛出错误。

SCRIPT5: Access is denied. jquery-2.0.2.js, line 1378 character 2
SCRIPT5009: '$' is undefined _display, line 21 character 1

将jQuery版本交换为1.9.1,一切正常。 http://jsfiddle.net/taneleero/pLRNF/3/

答案 1 :(得分:0)

$(document).ready的一次调用中保持一切完成,确保没有竞争条件等问题,而且调用添加的函数的顺序。

如果一个函数将元素添加到DOM而另一个函数需要它存在,则由于调用顺序的不同而可能会出现冲突和意外行为......