我的网站上有一个选择/下拉菜单,宽度为 150 像素,一些选项值非常长,我的问题是如果我选择一个长选项,它会在我的选择中切断。
我想以某种方式说,在更改时,修剪显示的值,使其只有 10 个字符并附加“...”
这可能吗?
你可以在这里看到我一直在尝试的东西......
与...
$('select').change(function(){
if($(this).val().length() >= 10){
alert('long title');
}
});
最佳答案
你可以这样做:
$('select').change(function(){
if(this.value.length >= 10){
console.log('long title');
//trimming
var trim = $.trim(this.value).substring(0, 10) + "...";
alert(trim);
//Set the text in the select
$(this).find("option:selected").text(trim);
}
});
关于jquery - 如果选择选项文本长度大于 10,则修剪 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17298766/