2014-10-16 59 views
0

我有jQuery中的以下内容:jQuery的传递函数的参数,以嵌套函数

$(".paid").each(function (i, tag) { 
    $(tag).change(function (i, tag) { 
     if ($(this).is(":checked")) { 
      alert($(tag).i); 
      $("invdesc_" + i).prop("disabled", false); 
     } 
    }) 
}); 

如何传递在$ i函数到$(标签).change功能(“支付”。)?

我需要更改.prop()基于来自PHP foreach()迭代的关键。

+0

变化检索它的参数$(标签).change(函数(J,TAG1) – Balachandran 2014-10-16 15:10:16

+0

这似乎过于你可以提供相同的HTML,因为这样做肯定会更简单。 – 2014-10-16 15:29:28

回答

1

你可以做到这一点

$(".paid").each(function(i, tag) { 
    $(tag).change({ index: i, elem: tag }, function(e) { 
     if ($(this).is(":checked")) { 
      alert($(e.data.elem)); // tag 
      $("invdesc_" + e.data.index).prop("disabled", false); // i 
     } 
    }) 
}); 

您可以通过eventData任何物体,并通过event.data