In Chrome debugger I get an Uncaught TypeError: undefined is not a function
when it parses this bit of code:
var pay = '{{payt}}';
if (pay.contains('visa')){
$('#visa').prop('checked', true);
}
However this causes no problems in Firefox and executes the code. What woould cause this error?
EDIT: indexOf()
works -
if (pay.indexOf("visa")!=-1){
$('#visa').prop('checked', true);
}
根据MDN文档 ,Chrome尚不支持.contains函数。
As the "undefined" user said, a polyfill is your best bet for ECMAScript functions that do not yet exist in the standard browsers.
if ( !String.prototype.contains ) {
String.prototype.contains = function() {
return String.prototype.indexOf.apply( this, arguments ) !== -1;
};
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.