简体   繁体   中英

Script is working with jquery 1.3.2 but not with jquery 1.7.2

I am trying to add extra input fields but this code works with jquery 1.3 once i try with jquery 1.7. It doesn't work

var newTr = $(document.createElement('tr'))
         .attr("id", 'line' + counter);

    newTr.after().html('<td><input type="text" name="name' + counter + 
          '" id="name' + counter + '" value="" style="width:100px;"></td><td><input type="text" name="phone' + counter + 
          '" id="phone' + counter + '" value="" style="width:100px;"></td>');

    newTr.appendTo("#dyTable");

I guess there is problem with newTr.after().html() and newTr.appendTo("#dyTable"); Please help me

document.createElement('tr') is not needed and you can simply use $('<tr></tr>') to create new element. This should work,

var newTr = $('<tr></tr>').attr("id", 'line' + counter);

For adding <td> content, change, newTr.after().html('...') to newTr.html('...') . I don't think after is required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM