[英]How can I pass a function reference with multiple arguments to the callback of my jQuery(document).on('click' event?
I have the following code definition 我有以下代码定义
$(document).on('click', firstRow, processEvent(firstRow, rowArray));
Which uses the parameters below. 使用以下参数。 As it currently stands I am passing the function
processEvent
rather than the function definition stored in the variable, and so the function is being invoked immediately. 就目前情况而言,我正在传递函数
processEvent
而不是传递给变量中存储的函数定义,因此该函数将立即被调用。
I wish to set up click handlers dynamically, and for my feature to work I need to be able to pass two parameters to the callback on the click event. 我希望动态设置点击处理程序,并且要使我的功能正常运行,我需要能够将两个参数传递给click事件的回调。 The first is a reference to the DOM element(s) the click is attached to, and the second is an array of DOM elements indentifiers (stored as strings) .
第一个是对单击附加到的DOM元素的引用,第二个是DOM元素标识符(存储为字符串)的数组。
How can I pass a function reference with multiple arguments to the callback of my jQuery(document).on('click' event? 如何将带有多个参数的函数引用传递给jQuery(document).on('click'事件的回调?
var firstRow = '.first-row';
var secondRow = '.second-row';
var thirdRow = '.third-row';
var rowArray = [firstRow, secondRow, thirdRow];
var hideRow = function(input){
var Input = input;
$(Input).show();
};
var showRow = function(input){
var Input = input;
$(Input).hide();
}
// alert(rowArray);
//Hide second and third rows
$('.second-row, .third-row').hide();
var processEvent = function(e, fooArray){ // currently set to one
var E = e; // Cache ID of calling object
var a = fooArray;
// alert(E);
// alert(a);
var arrayLength = a.length;
for (var i = 0; i < arrayLength; i++) {
foo = a[i];
// alert(row); //
alert(foo);
if (foo = e){
showRow(e);
}
else {
hideRow(foo);
}
}
} // function testProcessEvent(){ processEvent(); }
$(document).on('click', firstRow, processEvent(firstRow, rowArray));
This is my first attempt $(document).on('click', firstRow , someFunction(firstRow )); 这是我的第一次尝试$(document).on('click',firstRow,someFunction(firstRow));
Use 采用
$(document).on('click', firstRow, function () {
//place the code here
processEvent(firstRow, rowArray);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.