Drop down menu Angular 6以编程方式打开选择
我试图在angular 6中使用javascript打开选择选项Drop down menu Angular 6以编程方式打开选择,drop-down-menu,angular6,Drop Down Menu,Angular6,我试图在angular 6中使用javascript打开选择选项 const dropDown = document.getElementById(id); let event; event = document.createEvent('MouseEvents'); event.initMouseEvent('mousedown', true, true, window); dropDown.dispatchEvent(event); 也试过像 @ViewCh
const dropDown = document.getElementById(id);
let event;
event = document.createEvent('MouseEvents');
event.initMouseEvent('mousedown', true, true, window);
dropDown.dispatchEvent(event);
也试过像
@ViewChild('select') select: ElementRef;
func() {
this.select.nativeElement.open();
}
但它不起作用。我已经搜索并找到了材料和离子的结果。但是我怎样才能在第6页打开呢
@ViewChild('select') select: ElementRef;
func() {
this.select.nativeElement.focus();
}
使用focus()它将起作用。我认为这是不可能的,但您可以通过设置select的大小并使用position:absolute使其浮动来实现这一点
<div style="position:relative">.<select style="position:absolute;top:-8px;left:-20px" onClick="onAssign(this)">
<option>a</option>
<option>b</option>
<option>c</option>
</select></div>
function openMySelect(){
document.querySelector(‘#mySelect’),size=YOUR_OPTIONS.length;
}
function onAssign(data,select){
select.size=1
// your logic
}
。
A.
B
C
函数openMySelect(){
document.querySelector('#mySelect'),size=YOUR_OPTIONS.length;
}
函数onAssign(数据,选择){
选择。大小=1
//你的逻辑
}
不幸的是,这不起作用,select元素只聚焦,没有打开。