下拉框里的字太多了,下拉框会变长,然后把版面挤乱了,多余的如何显示成省略号?
或者限制住下拉框的跨度也行?
style="width:100px;"
这种已经试过了,没用!/option>
function cutoption(selectobj , length) {
this.selectobj = selectobj;
this.length = length;
}
cutoption.prototype.init = function() {
this.options = this.selectobj.getelementsbytagname('option');
for(i=0 , j=this.options.length ; i<j ; i++ )
{
text = this.options[i].firstchild.nodevalue;
if(text.length<=this.length)
{
return;
}
else {
this.options[i].innerhtml = text.substring(0,this.length) + '...';
}
}
}
obj = document.getelementbyid('a');
//想要几个字就改第二个参数;
var optionclass = new cutoption(obj , 2);
optionclass.init();
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]