我嘗試了幾件事情,試圖使這項工作,我不知道是否有可能。我有選擇的插件(http://harvesthq.github.io/chosen/)。我想要做的是以下幾點:jquery更新選項
- 檢查每一個選項
- 的長度,如果該選項比一定規模 更大*切,並添加「...」 *添加工具提示的充分字符串
工具提示工作正常,我不管理的是用新(...)字符串重新繪製選擇。所選的字符保持全字符串。
這裏是我的代碼
$("select").chosen().each(function() {
$(this).on("liszt:showing_dropdown", function() {
if($(this).parent().is('.myContentClass')){
$(this).next().find('li').each(function(){
var size = measureText($(this).text(), 12, 'Tahoma')
var limit = MyWidth - 50;
if(size.width > limit){
var tmp_str = $(this).text();
var dot_limit = MyWidth.width() - 60;
while(measureText(tmp_str, 12, 'Tahoma').width > dot_limit){
tmp_str = tmp_str.substring(0, tmp_str.length - 1);
}
tmp_str = tmp_str + '...';
//console.log(tmp_str) here im getting the correct string
$(this).attr('title', $(this).text());
$(this).text(tmp_str); // :(
//$("select").chosen().trigger("liszt:updated"); //not working
$('#tiptip_content').css('font-size', '13px');
$(this).tipTip({
maxWidth: "auto",
defaultPosition: "left",
fadeIn: 100,
fadeIn: 100,
attribute: "title"
});
}
$(this).trigger("change"); //not working
});
}
});
});
不是做所有這些工作,你認爲這樣使用CSS?所有你需要的是對每個項目,這些CSS規則: '溢出:隱藏;' '白色空間:NOWRAP;' '文本溢出:省略號;' –