欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

js trim

shiping1 的头像

String.prototype.ltrim=function()
{
    return this.replace(/^\s+/,"");
}
String.prototype.rtrim=function()
{
    return this.replace(/\s+$/,"");
}
String.prototype.trim=function()
{
    return this.ltrim().rtrim();
}


  var $dtTimeStart = $('#dtTimeStart').val().trim();
  var $dtTimeEnd = $('#dtTimeEnd').val().trim();
 

 

 

 

 

//this is for not IE and Other browser
String.prototype.trim = function(){
var str = this,ws = /\s/;
str = str.replace(/^\s+/, '');
var i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
String.prototype.quote = function () {
var c, i, l = this.length, o = '"';
for (i = 0; i < l; i += 1) {
c = this.charAt(i);
if (c >= ' ') {
if (c === '\\' || c === '"') {
o += '\\';
}
o += c;
} else {
switch (c) {
case '\b':
o += '\\b';
break;
case '\f':
o += '\\f';
break;
case '\n':
o += '\\n';
break;
case '\r':
o += '\\r';
break;
case '\t':
o += '\\t';
break;
default:
c = c.charCodeAt();
o += '\\u00' + Math.floor(c / 16).toString(16) +
(c % 16).toString(16);
}
}
}
return o + '"';
}
if(document.documentElement.__defineGetter__){
HTMLElement.prototype.__defineGetter__("currentStyle", function () {
return this.ownerDocument.defaultView.getComputedStyle(this, null);
});
}
var rselfClosing = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i;
var outerHTML = function(el,recursion){
switch(el.nodeType+""){
case "1":
var array = [];
var nodeName = el.nodeName;
if(recursion && el.currentStyle.display == "block"){
array.push("\n")
}
array.push("<"+nodeName);
for(var i=0,t;t=el.attributes[i++];){
array.push(" "+t.name+"="+(t.value||t.specified+"").quote())
}
if(rselfClosing.test(el.nodeName)){
array.push("\/>")
}else{
array.push(">");
for(var i=0,c;c=el.childNodes[i++];){
array.push(outerHTML(c,true))
}
array.push("<\/"+el.nodeName+">")
}
return array.join("");
case "3":
return el.nodeValue.trim();
case "8":
return "innerHTML" in el? el.innerHTML : "<!--"+el.nodeValue+"-->"
}
}
var innerHTML = function(el){
var array = [];
for(var i=0,c;c=el.childNodes[i++];){
array.push(outerHTML(c,true))
}
return array.join("");
}

普通分类: