有没有办法在单击其他按钮时打开下拉菜单?
9udxz4iz1#
给你!!
JS
function VM() { var message = ko.observable("hello!!"); function onButtonClick() { var dropdown = document.getElementById('dropdown'); showDropDown(dropdown); } function showDropDown(element){ var event; event = document.createEvent('MouseEvents'); event.initMouseEvent('mousedown', true, true, window); element.dispatchEvent(event); } return { message: message, onButtonClick:onButtonClick } } ko.applyBindings(new VM());
HTML格式
<button data-bind="click: onButtonClick"> Button </button> <select id="dropdown" > <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select>
下面是JSFiddle!及其解决方案更新了针对Knockout的How can you programmatically tell an HTML SELECT to drop down (for example, due to mouseover)?解决方案
1条答案
按热度按时间9udxz4iz1#
给你!!
JS
HTML格式
下面是JSFiddle!及其解决方案
更新了针对Knockout的How can you programmatically tell an HTML SELECT to drop down (for example, due to mouseover)?解决方案