有谁知道是否可以在 angularjs 中以编程方式打开选择。我试过了
angular.element(el).trigger('focus');
angular.element(el).trigger('click');
angular.element(el).trigger('mousedown');
没有任何作用。
我也尝试过
$scope.doSomething = function(){
setTimeout(function() {
var el = document.getElementById('test');
var e = document.createEvent("MouseEvents");
e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
worked = el.dispatchEvent(e);
}, 0);
}
上面设置焦点但不打开选择。
可能吗?
最佳答案
试试这个悬停:
JS:
$(document).ready(function(){
$("#selectId").hover(function(){
$(this)[0].size=$(this).find("option").length;
});
$("#selectId").click(function(){
$(this)[0].size=0;
});
});
HTML:
<select id="selectId">
<option>Volvo</option>
<option >Saab</option>
<option>Mercedes</option>
<option>Audi</option>
</select>
关于angularjs - 如何以编程方式打开选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23609105/