如何通过ajax jquery设置di​​v标签的属性值

时间:2012-09-18 10:58:48

标签: java ajax jquery

我想设置属性'data-rating'的值。它将使用Ajax。

<div id="fixed_<s:property value="messageId"/>" **data-rating=**"<%=averageScore%>"></div> from ajax function though jquery that is as below :

`

$.ajax({
type : "POST",
cache:false,
url : '<s:url action="ratingStatus"/>',
dataType: "text",
data : 'score=' +score+'&messageId='+<s:property value="messageId"/>+'&categoryId='+<s:property value="categoryId"/>+'&threadId='+<s:property value="threadId"/>,
success : function(data) {
alert("inside Success...");

//here i want to set div attribute(data-rating) value from action class response that i have made...



//location.reload();

}
});`

如果有人可以帮助我......

3 个答案:

答案 0 :(得分:4)

$("#fieldId").attr("data-rating","value want to set");

答案 1 :(得分:1)

$('#objectID').attr('data-rating', 'your value')

答案 2 :(得分:1)

成功功能

success : function(data) {

 $('#yourdivid').attr('data-rating','value from the response');
}