将数据传递给 jQuery 事件处理程序 [英] Passing data to a jQuery event handler

查看:28
本文介绍了将数据传递给 jQuery 事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 GUI 中,用户在文本输入中插入一些文本,然后单击按钮:插入的文本将显示在 div 中.

In a GUI, a user inserts some text in a text input and then clicks a button: inserted text will be displayed in a div.

我找到了一个简单的解决方案(demo here),即在里面设置输出文本访问输入元素对象的处理程序.糟透了.相反,我会将输入文本(而不是元素)传递给处理程序.

I have found a trivial solution (demo here), that is setting the output text inside the handler accessing the input element object. It sucks. Rather, I would pass the input text (not the element) to the handler.

如何将参数(在本例中为输入消息文本)传递给处理函数?

How can I pass parameters (the input message text in this case) to the handler function?

推荐答案

我修改了你的 jsFiddle.在 jQuery 中,您可以将数据作为参数传递并使用 event.data jQuery 参考访问它.

I modified the code in your jsFiddle. In jQuery, you can pass data as an argument and access it using event.data jQuery reference.

这篇关于将数据传递给 jQuery 事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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