有没有办法捕获html select事件,并防止html select下拉框打开?(禁用html select不被考虑,因为事件也会被禁用。)
有没有办法捕获html select事件,并防止html select下拉框打开?(禁用html select不被考虑,因为事件也会被禁用。)
<select name="theselect" onchange="this.selectedIndex = 1;">
<option value="Red">Red</option>
<option value="Green" selected="selected">Green</option>
<option value="Blue">Blue</option>
</select>
<optgroup>
而不是option
。然而,我困惑的是为什么您要禁用下拉菜单,但禁用它并不是一个选项...我同意Myles的观点:希望以下链接对你有所帮助:
自定义下拉菜单 http://jonathan.tang.name/code/jquery_combobox
Demo: http://jonathan.tang.name/files/jquery_combobox/demo.html
您可以从下拉列表中删除所有选项,或隐藏当前选择元素并将其替换为空元素。
<select id="main">
<option name="1">1</option>
<option name="2">2</option>
<option name="3">3</option>
</select>
<select id="empty" style="display:none;">
</select>
<script>
function disableSelect() {
document.getElementById('main').style.display = 'none';
document.getElementById('main').style.display = '';
}
</style>