开发者

How to make sure my jQueryUI button text isn't longer than 25 characters?

开发者 https://www.devze.com 2023-01-27 09:06 出处:网络
To avoid causing problems for my layout, how do I make sure my button text isn\'t longer than 25 characters?

To avoid causing problems for my layout, how do I make sure my button text isn't longer than 25 characters?

var fileName = "AnalysisOfCollateralDebt";

$('#buttonContainer')
.append("<button id='fileButton' class='span-1'>Show File" 
+ fileName 
+ "</button>");

$("#fileButton").button({
    icons: {primary: "ui-icon-triangle-1-e"},
    text: true
});

In the exam开发者_如何学Pythonple above, the button would read:

Show File: AnalysisOfCollateralDebt

but I want it to read:

Show File: AnalysisOf...


Just change line 5 to this:

+ fileName.substr(0,10) + ((fileName.length > 10)?'...':'')

in English:

fileName.substr(0,10): First 10 chars of the file name; if file name is shorter than 10 chars .substr() will have no effect.

((fileName.length > 10)?'...':''): if file name is indeed longer than 10 chars, print out '...'.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号