使用 jQuery.Trigger 发送/打印密钥

发布于 2024-08-31 05:13:53 字数 383 浏览 0 评论 0原文

我想我已经阅读了谷歌知道的包含这些关键字的每一页,但没有任何内容对我有用。

我拥有的是一个表单输入,旁边有一个按钮[不提交],我想要的是单击按钮来触发“输入”键单击。 [这将分别运行另一个已经在工作的函数..]

我已经尝试过

<input id='inputBtn' type='button' .... onclick='$('#otherInput').trigger('keypress',[13]);' >

并将其放入一个函数中,然后从 onclick 运行它,或者

$('#inputBtn').click(function().....

对我不起作用,请帮助!

i think i have read every page google knows about which has these keywords, and nothing works for me.

what i have is a form input, and a button next to it [not submit], and what i want is for the button click to trigger an 'enter' key click. [this will respectively run another function which is already working..]

i've tried

<input id='inputBtn' type='button' .... onclick='$('#otherInput').trigger('keypress',[13]);' >

and also putting it in a function and then running it from onclick, or making a

$('#inputBtn').click(function().....

nothing works for me please help!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

他是夢罘是命 2024-09-07 05:13:53
$('input').trigger({
  type:  'keypress',
  which:  13
});

--编辑--

你可能想用

keyCode: 13,
charCode: 13

等等来扩展它。

$('input').trigger({
  type:  'keypress',
  which:  13
});

--EDIT--

you might want to extend that with

keyCode: 13,
charCode: 13

etc.

絕版丫頭 2024-09-07 05:13:53

您可能需要提供一些示例代码。我想不出有什么理由不能让按钮上的单击事件调用第二个函数(按下 Enter 键时运行)。

function onEnter()
{
 //Do something
}

jQuery("#inputButton").live("click",onEnter());

应该有效。

You might need to provide some example code. I can't think of any reason you couldn't just have the second function (that runs when enter is pressed) being called by the click event on your button.

function onEnter()
{
 //Do something
}

jQuery("#inputButton").live("click",onEnter());

Should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文