我有一个:
$('#product_category > option:selected').each(function()
并将其附加到带有
.append(<div>'+$(this).text()+'</div>);
但我想只显示9个字符的文字。如果长度大于9,则写第一个9和+“ ...”
香港专业教育学院尝试:
$('#product_category > option:selected').each(function() {
var text = $(this).text();
if(text.val().length > 8)
{
text = text.substr(0,9)+"...";
}
$('#confirm-category').append('<div class="alert alert-success">'+text+'</div>');
});
但它不起作用:/
我会很乐意的帮助:)
改变你的if条件
if(text.val().length > 8)
到
if(text.length > 8)
您不需要val()
那里了,因为您已经有了它的文本text()
。
var text = $(this).text(); //<---here
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句