$("#phoneR").find("input#phone").remove();
for (var i = 1; i <= para[3] - 1; i++) {
$("#phoneR").find("td:eq(1)").after(" <input 开发者_如何学JAVAtype='text' name='phone[]' disabled='disabled'/>");
}
The code above is suppose to iterate and add the input 3 times, but for some reasons what soever it's not doing. Is it that.
Am i doing something wrong.
@cyberomin
Have you checked the result of this?
$("#phoneR").find("td:eq(1)")
td:eq(1) retrieves the second td element that is found inside $("#phoneR")
. If you really want the first td, then you'll have to do:
$("#phoneR").find("td:eq(0)")
Try to do $("#phoneR").find("td:eq(1)").length
and make sure it equals 1.
Alternatively, you can use the :first selector, which is equivalent to :eq(0)
$("#phoneR").find("td:first")
I have the feeling this would probably sound as a stupid question, but what's wrong with this approach?
for (var i = 1; i < 3; i++)
I mean, if you want to add exactly 3 inputs, then i < 3 would suffice
anyways, since you most probably will require the para variable, I would suggest caching it before going into the loop, as this would need to calculate para[3] - 1 three times instead of one
var para_3 = para[3] - 1;
for (var i = 1; i <= para_3; i++)
精彩评论