jQuery源码分析7: jQuery.trim
// Used for trimming whitespace
var trimLeft = /^\s+/,
trimRight = /\s+$/,
trim = String.prototype.trim;
//< JavaScript直到1.8.1才支持trim
// Check if a string has a non-whitespace character in it
rnotwhite = /\S/,
//< 在ie中不换行符号non-break('\xA0')不算作空白,即不在字符集[\s]中,但在其他浏览器则属于空白,所以在jQuery中针对ie作了加强处理
if ( rnotwhite.test( "\xA0" ) ) {
trimLeft = /^[\s\xA0]+/;
trimRight = /[\s\xA0]+$/;
}
// < 若支持原生的String.prototype.tim则直接使用其过滤字符串两侧的空白,否则使用replace过滤两侧的空白
trim: trim ?
function( text ) {
return text == null ?
"" :
trim.call( text );
} :
// Otherwise use our own trimming functionality
function( text ) {
return text == null ?
"" :
text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
},
补充
最后需要提到的是ECMA-262(V5)中为String提供原生的trim方法.此外Molliza Gecko 1.9.1引擎中还给String添加了trimLeft,trimRight方法.
分享到:
相关推荐
11.String.Trim() 54 12.String.Insert(pos, str) 54 13.String.Remove(start) 55 14.String.Remove(start, length) 55 15.String.Replace(find, replace) 55 LINQ to SQL语句(16)之对象标识 56 对象标识 56 对象...
9. 去空格函数:trim 25 10. 左边去空格函数:ltrim 25 11. 右边去空格函数:rtrim 25 12. 正则表达式替换函数:regexp_replace 26 13. 正则表达式解析函数:regexp_extract 26 14. URL解析函数:parse_url 26 15. ...
String.prototype.trim 符合ES5规范的String.prototype.trim填充程序。 如果不可用,请调用其“ shim”方法对String.prototype.trim进行填充。 该软件包实现了接口。 它可以在ES3支持的环境中工作,并符合规范( ...
case R.id.button7: editText1.setText(str + "6"); break; case R.id.button8: num1=Double.parseDouble(str); temp="-"; editText1.setText(" "); break; case R.id.button9: editText1.setText(str + "3"); ...
jQuery基础 隔行变色的表格 window.onload=function(){ var otable = document.getElementById('oTable'); for(var i=0 ; i<otable.rows.length ; i++){ if(i%2==0) otable.rows[i].className = 'alrow'; } } $...
android视频硬解码压缩,100M视频压缩至10M内仅需10s左右
int W = Convert.ToInt32(this.txtWidth.Text.Trim()); int H = Convert.ToInt32(this.txtHeight.Text.Trim()); int AddNum = Convert.ToInt32(this.tbAddNum.Text.Trim()); int SerialNo = Convert.ToInt32...
trim函数.txt
selection=(selection==null||"".equals(selection.trim()))? _id+"="+id:selection+"and"+_id+"="+id; num=sqLiteDatabase.update(Table_Name, values,selection, selectionArgs); default: break...
jquery需要的所有js文件 /*! * jQuery UI 1.8.18 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT or GPL Version 2 licenses. * http://jquery.org/license * ...
11.5.1 jQuery.trim(str) 194 11.6 URL 194 11.6.1 jQuery.param(obj, [traditional]) 194 11.7 插件编写 196 11.7.1 jQuery.error(message) 196 12. 关于 197 12.1 关于jQuery 中文文档 197 12.2 关于jQuery 1.3 版...
在jQuery中,工具函数是指直接依附于jQuery对象,针对jQuery对象本身定义的方法,即全局性的,我们统称为工具函数,或Utilites函数 主要作用于:字符串、数组、对象 API:工具函数 调用格式: $.函数名()或jQuery.函数名...
技巧:MyBatis 中的trim标签,好用!.zip技巧:MyBatis 中的trim标签,好用!.zip技巧:MyBatis 中的trim标签,好用!.zip技巧:MyBatis 中的trim标签,好用!.zip技巧:MyBatis 中的trim标签,好用!.zip技巧:...
建议为.trim() 、 .trimStart()和.trimEnd()添加参数以允许从字符串中.trimEnd()指定的字符。 地位 该提案是,等待反馈。 动机 我们经常通过trim 、 trimStart和trimEnd从字符串的开头或结尾(或两者)删除一些前导/...
jQuery.trim()函数用于去除字符串两端的空白字符。jquery trim函数应用非常广泛,下面小编给大家讲解jquery.trim()函数及trim()用法详解,需要的朋友可以参考下
xml/ns/javaee":deferred-syntax-allowed-as-literal, "http://java.sun.com/xml/ns/javaee":trim-directive-whitespaces, "http://java.sun.com/xml/ns/javaee":default-content-type, ...
VB写的计算广发行信用卡提现手续费及利息的小工具,不包含滞纳金的计算! 广发银行提现手续费按2.5%收取,... If Trim(Text1.Text) <> "" And Trim(Text2.Text) <> "" And KeyAscii = 13 Then Command1_Click End Sub
一个便捷的javascript封装的工具包,如果你熟悉jquery的话,那么对于这里面的函数一定会让你感到很上手,因为设计思路类似于jquery,里面封装了一些非常常用dom操作、ajax等函数,例如: 去除字符串两边的空格 var result ...
类似如下: select A.key,B.key,C.key from A,B,C where trim(A.key)=trim(B.fk) and trim(A.col)=trim(C.pk)。 在主表A(200多条记录)关联附表B(4万多条记录)时用了1秒钟时间,该值在不同机器执行可能有所差异,但...
用于 benchmark.js 的 Benchmark Suite Runner 安装 新产品经理 npm install benchrunner 鲍尔 bower install benchrunner 用法 你可以写一个这样的套件: (function(root) { ... ' foo '.trim