以下代码会导致浏览器崩溃。对于Firefox,我已经给出了一个选择,不管我是否想停止jQuery,因为它的运行时间比它应该的长。jQuery不选择导致无限循环
div id="divLeaving">
You are about to leave to: <span id="spanLeavingURL"></span>
<a id="divLeavingYes" href="#">Yes</a><a id="divLeavingNo" href="#">No</a>
</div>
<a href="http://www.google.com">google</a>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("a:not(#divLeavingYes, #divLeavingNo)").click(function() {
var url = $(this).attr("href");
var test_if_local = url.indexOf("mycompany.com");
if (test_if_local == -1) {
$("#spanLeavingURL").text(url);
$("#divLeavingYes").attr("href", url);
$("#divLeavingNo").click(function() { $(this).dialog('destroy'); });
$("#divLeaving").dialog({ modal: true });
return false;
}
});
});
</script>
但是,如果我删除不选择它不会崩溃我的浏览器。
<div id="divLeaving">
You are about to leave to: <span id="spanLeavingURL"></span>
<a id="divLeavingYes" href="#">Yes</a><a id="divLeavingNo" href="#">No</a>
</div>
<a href="http://www.google.com">google</a>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("a").click(function() {
var url = $(this).attr("href");
var test_if_local = url.indexOf("mycompany.com");
if (test_if_local == -1) {
$("#spanLeavingURL").text(url);
$("#divLeavingYes").attr("href", url);
$("#divLeavingNo").click(function() { $(this).dialog('destroy'); });
$("#divLeaving").dialog({ modal: true });
return false;
}
});
});
</script>
如何更改查询,以便选择除#divLeavingYes和#divLeavingNo之外的所有项目?
上面的代码不会使Firefox崩溃。是否还有更多代码可以包含? –