如何通过onClick事件将参数传递给jquery函数? [英] How to pass argument to a jquery function through an onClick event?
本文介绍了如何通过onClick事件将参数传递给jquery函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
jquery .click将参数传递给用户功能
Possible Duplicate:
jquery .click pass parameters to user function
$('#topleft').click(function (x) {
loadPopupBox();
$("#popupinner").load('getdetail.php?id=' +x);
});
如何通过onclick事件将值传递给变量x?变量x的值被发布到getdetail.php,并且将从getdetail.php返回的数据加载到ID为popupinner的DIV中.现在,除了数据POST/GET之外,其他所有东西都可以正常工作.
How to pass a value to the variable x from an onclick event? The value of the variable x is POSTED to getdetail.php and the data returned from the getdetail.php is loaded to a DIV with ID popupinner. Now everything works except the data POST/GET.
推荐答案
尝试使用 .click
语法为.click( [eventData], handler(eventObject) )
.
请参见下文
// v- Pass data
$('#topleft').click({x:x}, function (event) {
loadPopupBox();
$("#popupinner").load('getdetail.php?id=' + event.data.x); //read data from event obj
});
[eventData] x
可以作为event.data.x
The [eventData] x
can be accessed as event.data.x
这篇关于如何通过onClick事件将参数传递给jquery函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文