码迷,mamicode.com
首页 > Web开发 > 详细

jQuery 工具类函数-字符串操作函数

时间:2014-11-27 10:24:31      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   java   strong   on   

调用名为$.trim的工具函数,能删除字符串中左右两边的空格符,但该函数不能删除字符串中间的空格,调用格式为:

$.trim (str);

参数str表示需要删除左右两边空格符的字符串。

<body>
    <div id="divtest">
        <div class="title">
            <span class="fl">字符串操作函数</span> 
            <span class="fr">
                <input id="btnShow" name="btnShow" type="button" value="计算" />
            </span>
        </div>
        <div class="content">
            <input id="txtName" name="txtName" type="text" />
            <div class="tip"></div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            $("#btnShow").bind("click", function () {
                $(".tip").html("");
                var strTmp = "内容:";
                var strOld = $("#txtName").val();
                var strNew =$.trim(strOld);
                strTmp += strOld;
                strTmp += "<br/><br>除掉空格符前的长度:"
                strTmp += strOld.length;
                strTmp += "<br/><br>除掉空格符后的长度:"
                strTmp += strNew.length;
                $(".tip").show().append(strTmp);
            });
        });
    </script>
</body>

内容: dfddf 

除掉空格符前的长度:9

除掉空格符后的长度:5

jQuery 工具类函数-字符串操作函数

标签:style   blog   io   ar   color   sp   java   strong   on   

原文地址:http://www.cnblogs.com/boyzi/p/4125627.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!