这是我的 html 代码
<div data-percent="" ></div>
这是我的 JavaScript
function retrieveProgressbar(){
$.ajax({
type:"post",
url:"retrieveprogressbar.php",
data:"progressbar",
success:function(data){
$(this).data("percent").html(data);
}
});
}
retrieveProgressbar();
我需要将ajax检索到的值显示在data-percent=""中。我不知道该怎么做。我有另一个 javascript 需要使用这个值来执行。
最佳答案
需要使用.attr()方法。
<div data-percent="" id="datadiv"></div>
<script>
function retrieveProgressbar() {
$.ajax({
type: "post",
url: "retrieveprogressbar.php",
data: "progressbar",
success: function (data) {
//$("#datadiv").attr("data-percent", data);
// OR
$(this).attr("data-percent", data);
}
});
}
retrieveProgressbar();
</script>
关于javascript - 是否可以通过 jquery 将值传递到 <div data-value =""> ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48115097/