ie8ブラウザーは、endsWith、
trim()、
startsWithなどのメソッドをサポートしていないため、 使用中に互換性の問題が発生します
解決策:
上記のメソッドを書き換えます。
1、トリム、ltrimまたはrtrim
正規表現を使用する
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim=function(){
return this.replace(/(^\s*)/g,"");
}
String.prototype.rtrim=function(){
return this.replace(/(\s*$)/g,"");
}
2. StartWith rewrite
String.prototype.startWith=function(str){
if(str==null||str==""||this.length==0||str.length>this.length)
return false;
if(this.substr(0,str.length)==str)
return true;
else
return false;
return true;
}
//或者使用正则表达式,方法如下
String.prototype.startWith = function(str) {
var reg = new RegExp("^" + str);
return reg.test(this);
3. endWithを書き換えます
String.prototype.endWith=function(str){
if(str==null||str==""||this.length==0||str.length>this.length)
return false;
if(this.substring(this.length-str.length)==str)
return true;
else
return false;
return true;
}
//或者使用正则表达式
String.prototype.endWith = function(str) {
var reg = new RegExp(str + "$");
return reg.test(this);
}
注:
上記の方法:すべて$(function(){
上記の方法
});