[英]Why doesn't this simple script work in IE11
我的應用程序有問題,並且通過將代碼縮小為問題的根源來重新創建了相同的問題。 IE11在控制台中返回錯誤“'test1_1'未定義”
該代碼在Firefox中有效,因此我需要了解為什么它在IE11中不起作用。 希望它的東西直接任何幫助將不勝感激。
jQuery的:
function testAlert(row,defect){
alert(defect);
};
HTML:
<form>
<div class="input-group">
<input type="text" id="test1_1" name="test1_1" style="width:150px" readonly="true" value="test">
<span class="btn btn-default btn-sm input-group-addon"
id="customer_search"
onclick="testAlert('1',$(test1_1).val());
">
test
</span>
</div>
</form>
並非所有瀏覽器都為具有id的元素設置全局變量。 而且他們並不總是以相同的方式做。 因此,使用window.yourNodeId
通過其ID獲取元素是不可靠的,並且是一種不好的做法,您應該在此處使用選擇器:
onclick="testAlert('1',$('#test1_1').val());"
您忘記了'#'
onclick="testAlert('1',$('#test1_1').val());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.