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 '...'
.
精彩评论