1/3. Caption Text
2/3. Caption Two
3/3. Caption Three

Featured Post

吉他C大调音阶记忆和练习

在 jQuery 中如何确定字符串长度及其像素长度?

在 jQuery 中如何确定字符串长度及其像素长度?
2012年03月31日 IT点滴 | 浏览 13,681 暂无评论
1. 找出字符串的长度:
  1. <div class=".selector">Getting Started With jQuery</div>   
  2.   
  3. <script>   
  4.       var $char_length = $('.selector').text().length;   
  5. </script>  
2. 找出字符串的像素长度:
先把字符串及其属性放在 <span> 里面,然后,使用 jQuery 求得该 <span> 的像素宽度。如:
  1. <span id='string_span' style='font-weight: bold; font-size: 12'>Here is my string</span>   
  2.   
  3. <script>   
  4.        var $px_lenth = $('#string_span').width();   
  5. </script>  

No comments:

Post a Comment