我有javascript文件使用jQuery的份額,稱之爲common.js,其使用的2頁,說hello.html的和world.html。腳本包括事件處理程序:當選擇器爲空時,jquery選擇器在IE中彈出錯誤消息?
$("#helloPageButton").click(function() { ... });
$("#worldPageButton").click(function() { ... });
這一切都在Chrome,Firefox的正常工作,但在IE hello.html的拋出錯誤說「對象預期」那些選擇的路線。
如何獲取IE到不會拋出錯誤並在上移動如果未找到選擇器,即 - 爲空?
再舉一例:這並不在IE瀏覽器:
<html>
<body>
<input type="button" id="helloButtonID" value="This is the hello button">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$("#worldButtonID").click(function(){
alert("The world button is not on the webapge.");
});
</script>
</body>
</html>
jQuery不會前檢查按鈕是否存在選擇器不匹配任何元素時不返回null;它返回一個空數組。你會發表整個聲明嗎? – jalynn2
jalynn2我只是添加了一些代碼來顯示IE中的問題,謝謝! – fandang