以下代碼會導致瀏覽器崩潰。對於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崩潰。是否還有更多代碼可以包含? –