jQuery click event firing immediately

前端 未结 2 742
误落风尘
误落风尘 2021-01-26 07:19

I have the following code in the web app I\'m developing:

var bgcolor = \'\';
var row = 0;
for(var i = 0; i < result.data.length; i++)
{
    // Set alternatin         


        
2条回答
  •  伪装坚强ぢ
    2021-01-26 08:10

    You are calling the function yourself here .click( show_result_dialog(i, result) ); There is a difference between invoking a function show_result_dialog() and passing its reference show_result_dialog.

    You need to either pass your arguments as event data:

    .click( {index: i, result: result}, show_result_dialog );
    

    or simply wrap it in an anonymous function:

    .click( function() { return show_result_dialog(i, result) });
    

提交回复
热议问题