<div class="htmlarea"> <textarea id="runcode37083"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>脚本之家 www.jb51.net js下拉框省略号</title> <select id="a"> <option slected="slected">下拉框里的字太多了,下拉框会变长,然后把版面挤乱了,多余的如何显示成省略号?</option> <option>或者限制住下拉框的跨度也行?</option> <option>style="width:100px;"</option> <option>这种已经试过了,没用!/option> </option></select> <script type="text/javascript"> 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(); </script> </textarea><br><input onclick="runEx('runcode37083')" type="button" value="运行代码"> <input onclick="doCopy('runcode37083')" type="button" value="复制代码"> <input onclick="doSave(runcode37083)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>