【问题标题】:Textbox focus, need to trigger the keydown event for that textbox文本框焦点,需要触发该文本框的keydown事件
【发布时间】:2016-10-04 10:42:54
【问题描述】:

我想在文本框成为焦点时触发 keydown 事件。因此,当我专注于该文本框时,谷歌地图自动完成“place_changed”会正常工作。

【问题讨论】:

  • 如果你想触发 keydown 是 JavaScript 而不是 PHP,你不能通过 PHP 做到这一点
  • 是的,我只想在 javascript 中做。
  • @ban17 ,是的,我只想在 javascript 中做

标签: textbox focus keydown


【解决方案1】:

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'>

【讨论】:

  • 感谢触发器工作正常。我想要的gmap自动完成地址需要选择第一个.pacitem然后触发“place_changed”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多