Prevent select dropdown to open but allow its even

2019-02-17 13:25发布

Is there any way I can trap html select events, and prevent the html select dropdown to open? (Disabling html select is ruled out since the events will be disabled too.)

5条回答
The star\"
2楼-- · 2019-02-17 13:38

This doesn't disable the "dropdown to open", but if you don't want anything selectable, a trick I used was to make <optgroup> instead of option. However, I'm confused why you would want to disable the dropdown, but disabling it is not option...

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-02-17 13:42

You could remove all of the options from the dropdown, or hide the current select element and replace it with an empty one.

<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>
查看更多
Melony?
4楼-- · 2019-02-17 13:45

If you don't want to drop down a drop down box then why make it a drop down control.

Use an image that looks like a drop down and set it as the background if you need to get the feel of a drop down box.

查看更多
冷血范
5楼-- · 2019-02-17 13:49

I doubt this will actually prevent it from opening, but it will ensure that the DropDown will always maintain the same value:

<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>
查看更多
一纸荒年 Trace。
6楼-- · 2019-02-17 13:54

I second what Myles says: You hope you find these links useful:

Making custom dropdowns http://jonathan.tang.name/code/jquery_combobox

Demo: http://jonathan.tang.name/files/jquery_combobox/demo.html

查看更多
登录 后发表回答