2016-10-04 84 views

回答

0

var el=document.getElementById('inputID'); 
 
el.addEventListener("keydown", function(){ 
 
console.log('press'); 
 
}); 
 
Node.prototype.fire=function(type,options){ 
 
    var event=new CustomEvent(type); 
 
    for(var p in options){ 
 
     event[p]=options[p]; 
 
    } 
 
    this.dispatchEvent(event); 
 
} 
 
el.addEventListener("focus", function(){ 
 
    el.fire("keydown",{ctrlKey:true,keyCode:90,bubbles:true}) 
 
});
<input id='inputID'>

如果要觸發的keydown它的JavaScript不是PHP
+0

謝謝觸發器工作正常。我想在gmap自動完成地址中需要選擇第一個.pacitem,然後觸發「place_changed」。 – user3898169

相關問題