我想知道是否有方法在将输入值附加到文档之前设置输入值(通过ajax调用返回)。设置通过ajax返回的html字符串中的输入值
$(function() {
$("#addItem").click(function() {
var numRows = $('.row').length;
$.ajax({
url: this.href,
cache: false,
success: function (html) {
// find input id in html that contains Order ?
// set value of the input to numRows + 1 ?
// append updated html to an element called #rows
$("#rows").append(html);
}
});
return false;
});
感谢所有帮助
这里的HTML可能看起来像
+0
给我们返回的HTML的样本,所以我们可以给你一个答案。 –
2011-06-15 15:41:42
+1
顺便说一句,如果ID始终以'Order'结尾,则可以使用jQuery ['attribute-ends-width-selector'](http://api.jquery.com/attribute-ends-with-selector/)。 '$ html.find('input [id $ = Order]')' –
2011-06-15 16:00:29
+0
Thanks matt!我不知道这可以做到。 –
2011-06-15 16:26:20