如何使用JQuery发送按键触发器 [英] How to send a keypress trigger using JQuery

查看:266
本文介绍了如何使用JQuery发送按键触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何发送特定keyCode的触发按键,例如。使用JQuery编程的TextBox上的9事件?



这是我打算做的事情;
以编程方式向TextBox输入值,然后以编程方式触发TextBox上的Tabkey以退出该字段。



我的代码

  $(#tags1)。val(comp)//很好地运作

$(#tags1)。触发器( 按键,[9]); //失败!

Gath

解决方案 div>

jQuery文档声明它只会传递规范化的事件属性= jQuery.Event对象的属性,它们似乎没有包含特定于事件的数据。



我试过了,即使重复使用浏览器按键创建的事件对象,也无法将文本插入到文本框中,因此似乎不可能。



为什么你不能只改变文本框的值,并调用blur()来退出它? (或重点()你想进入下一个?)


How do i send a trigger keypress of a particular keyCode eg. "9" event on a TextBox using JQuery programmatically?

This what i intend to do; Programmatically enter a value to a TextBox and then programmatically trigger a tabkey on the TextBox to exit the field.

my code

$("#tags1").val("comp") // Works well

$("#tags1").trigger("keypress",[9]); // Fails!!

Gath

解决方案

The jQuery documents state that it'll only pass normalized event attributes = the properties of the jQuery.Event object, which don't seem to include event-specific data.

I tried, and couldn't get it to insert text into a textbox even when reusing an event object that a browser keypress created, so it doesn't seem to be possible.

Why can't you just change the value of the textbox, and call blur() to exit it? (Or focus() on the one you want to enter next?)

这篇关于如何使用JQuery发送按键触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆