$(document).on('click', '#my', myFunc('param'));

function myFunc(param){
    //do something
}


snytax错误吗?我收到jquery-1.10.2.min.js:3 Uncaught TypeError: ((x.event.special[i.origType] || (intermediate value)).handle || i.handler).apply is not a function的错误

最佳答案

您可以将数据对象作为on()的第三个参数发送,如下所示:

$(document).on('click', '#my', {p: 'World'}, myFunc);


并且在函数中,触发事件的方式如下所示,您可以使用event.data访问数据对象:

function myFunc(event) {
  console.log('Hello, ' + event.data.p);
}


请参见Passing data to the handler部分的此页面:http://api.jquery.com/on/#passing-data

关于javascript - 使用on()将参数传递给函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37294712/

10-12 15:18