我有一个从服务器,得到一个简单的Ajax请求生成的HTML,如:
I have a simple ajax request which get from server a generated HTML, like:
$.ajax({
url: '/GetData'
type: "POST",
dataType: "html",
data: ...,
success: function(data) {
// here I want to change `name` attributes of inputs
// before print on page
// but it doesn't work, so, how to manage this ?
$(data).find("input[name='test']").prop("name", "anotherValue");
$("myDiv").prepend($(data));
}
});
和我的动作很简单:
[HttpPost]
public ActionResult GetData(){
return PartialView("myview", new MyModel());
}
我想更改输入名称
属性之前打印出来的HTML页面。如果我在成功
函数(见上文),则不会进行任何更改。
I want to change input name
attributes before print them in html page. If I do in success
function (see above) then no change is made.
为什么呢?为了实现这一目标?
Why ? To to achieve this ?
尝试像
$("input").each(function() {
if($(this).prop("name") == "test") $(this).prop("name", "anotherValue");
});