java 如何通过ajax jquery设置div标签的属性值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12475643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:03:49 来源:igfitidea点击:
how to set attribute value of div tag through ajax jquery
提问by Hardik Lotiya
I want to set value of attribute 'data-rating'. It will use Ajax.
我想设置属性“数据评级”的值。它将使用 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();
}
});`
Please help me if any one can....
如果有人可以,请帮助我......
回答by sathish kumar
$("#fieldId").attr("data-rating","value want to set");
回答by Davecz
$('#objectID').attr('data-rating', 'your value')
回答by coolguy
Inside your success function
在您的成功函数中
success : function(data) {
$('#yourdivid').attr('data-rating','value from the response');
}