1. 找出字符串的长度:
- <div class=".selector">Getting Started With jQuery</div>
-
- <script>
- var $char_length = $('.selector').text().length;
- </script>
2. 找出字符串的像素长度:
先把字符串及其属性放在 <span> 里面,然后,使用 jQuery 求得该 <span> 的像素宽度。如:
- <span id='string_span' style='font-weight: bold; font-size: 12'>Here is my string</span>
-
- <script>
- var $px_lenth = $('#string_span').width();
- </script>
No comments:
Post a Comment