簡體   English   中英

jQuery未捕獲的TypeError

[英]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;
  };
}

來源: String.prototype.contains()的MDN

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM