我有下面的JSON对象返回给我,并且想要更新页面上已经存在的两个文本框(txtAssigned01和txtAssigned02)的val()。我知道我应该用循环做这件事,但不知道如何动态选择jQuery中的文本框。任何帮助,将不胜感激!循环通过JSON对象并动态输出到带有jQuery的文本框
JSON对象:
到目前为止的代码:
function getAssignedPerson(projectID) {
$.ajax({
url: "view-requests.aspx/getAssignedPerson", // Current Page, Method
data: JSON.stringify({
projectID: projectID
}), // parameter map as JSON
type: "POST", // data has to be POSTed
contentType: "application/json", // posting JSON content
dataType: "JSON", // type of data is JSON (must be upper case!)
timeout: 10000, // AJAX timeout
success: function (result) {
$.each(result, function (i, v) {
$('#txtAssigned0'+ v).val(result.d[i]); <--- here's my problem
});
},
error: function (xhr, status) {
alert(status + " - " + xhr.responseText);
}
});
}
你试过.attr(“name”,“somename”)? –