[英]JQuery Uncaught TypeError
在Chrome調試器中,我收到Uncaught TypeError: undefined is not a function
解析此代碼段時, Uncaught TypeError: undefined is not a function
:
var pay = '{{payt}}';
if (pay.contains('visa')){
$('#visa').prop('checked', true);
}
但是,這在Firefox中不會引起任何問題並執行代碼。 是什么會導致此錯誤?
編輯: indexOf()
工作-
if (pay.indexOf("visa")!=-1){
$('#visa').prop('checked', true);
}
根據MDN文檔 ,Chrome尚不支持.contains函數。
正如“未定義”用戶所說,對於標准瀏覽器中尚不存在的ECMAScript函數,polyfill是您的最佳選擇。
if ( !String.prototype.contains ) {
String.prototype.contains = function() {
return String.prototype.indexOf.apply( this, arguments ) !== -1;
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.