我有一个选择框,其类属性设置为class="styled"
。原因是选择框已设置样式(它使用背景 url 为其提供自定义外观)。如果我删除这个类属性,我可以简单地在 html 标签中使用 size="10"
,或者动态更改它:
var o_select = document.getElementById("mySelect");
o_select.size = "10";
(或,o_select.setAttribute("size", "10");
)
这似乎是导致问题的类属性。请帮忙!
最佳答案
这很好用
<select class="styled" id="mySelect">
<option>This is an option</option>
<option>This is another option</option>
</select>
和
var o_select = document.getElementById("mySelect");
o_select.size = "10";
http://jsfiddle.net/jasongennaro/LSP8p/1/
您还发生过哪些其他 HTML/JS 操作?
关于Javascript设置选择框大小属性似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6927669/