2011-02-14 68 views
0

我已经附加了输入元素表行到现有的表如下:我如何maniputate jQuery的追加到现有的表的表行

$("#additems_table").append(
"<tr><td style='color:#999; font-size:16px;'>"+(counter++)+"</td><td> 
<select class='item'><?php while($product_rows=mysql_fetch_assoc($productSQL)){?><option value='<?php echo $product_rows['pid']; ?>'><?php echo $product_rows['name']; ?></option><?php }?></select></td><td id='quantity_td'><input name='quantity' class='quantity' type='text' style='width:35px' id='cost"+(numqty++)+"' /><input type='hidden' name='price_hf' id='cost"+(numprice++)+"'/></td><td id='amount_td'><input name='amount' id='cost"+(numamount++)+"' style='width:70px' type='text' value='3' disabled='disabled'/></td></tr>"); 
}); 

问题进来时,我试图操纵中的这些元素以上附加的行。它根本不听任何事件,点击,改变等。例如

$("#additems_table input[type=text]").each(function(){ 
    $(this).change(function(){   
     alert("amount"); 
    }); 
}) 

我真的很感谢帮助。

+0

请你可以发布一个格式化的代码示例,理想的代码传递给浏览器,而不是jQuery和php的组合。 – 2011-02-14 15:18:03

回答

1

OK,到线了新的输入元素做线沿线的东西:

$(function(){ 

    $('#additems_table input[type="text"]').live('change', function(){ 

    }); 
}); 

这也就意味着:负载创建其内部的#additems_table所有元素的变化事件在全球处理器。实时方法可以实时创建新元素(输入文本框),而无需担心其事件注册。新添加的元素的change事件将触发并自动处理。