1 IE 浏览器不支持事件和方法的解决方案:
1.1 trim()
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,"");
}
1.2 startsWith()
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);
}
String.prototype.startsWith = function (prefix){
return this.slice(0, prefix.length) === prefix;
};
1.3 endsWith()
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);
}
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
2 谷歌、火狐浏览器不支持事件和方法的解决方案
2.1 onpropertychange
function onpropertychange(){
var element = document.getElementById("inputID");
if("/v"=="v") {
element.onpropertychange = textChange;
}else{
element.addEventListener("input",textChange,false);
}
function textChange(){
alert(element.value);
}
};
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
$("#inputID").bind("input propertychange",function(){
alert($("#inputID").val());
});
来源:oschina
链接:https://my.oschina.net/u/4466106/blog/4406069