开发者

how do i maniputate table rows appended to an existing table in jquery

开发者 https://www.devze.com 2023-02-10 15:10 出处:网络
I have appended table rows with input elements to an existing table as follows: $(\"#additems_table\").append(

I have appended table rows with input elements to an existing table as follows:

$("#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>");
});

The problem come in when i try to manipulate these elements within the above appended rows.It simply does not listen to any event, click, change, etc. e.g

$("#additems_table input[type=开发者_高级运维text]").each(function(){
    $(this).change(function(){          
        alert("amount");
    });
})

I will really appreciate the help.


ok, to wire up the new input elements do something along the lines of:

$(function(){

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

    });
});

What that means is: on load create a global handler for the change event of all elements that are inside the #additems_table. The live method makes it possible to create new elements (input textboxes) on the fly without having to worry about their event registration. The change event of the newly appended elements will fire and will be handled automatically.

0

精彩评论

暂无评论...
验证码 换一张
取 消