Display only 10 characters of a long string?

前端 未结 12 2107
臣服心动
臣服心动 2020-12-13 01:19

How do I get a long text string (like a querystring) to display a maximum of 10 characters, using JQuery?

Sorry guys I\'m a novice at JavaScript & JQuery :S

12条回答
  •  悲哀的现实
    2020-12-13 02:07

    Although this won't limit the string to exactly 10 characters, why not let the browser do the work for you with CSS:

    .no-overflow {
        white-space: no-wrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }
    

    and then for the table cell that contains the string add the above class and set the maximum permitted width. The result should end up looking better than anything done based on measuring the string length.

提交回复
热议问题