<分区>
我发出了一个 Ajax 请求,之后我更改了一个属性值。在 DOM 中,一切都按预期发生变化。但是当我再次单击该按钮时,旧的属性值显示在控制台中。看起来他没有看到标记中的变化并加载旧数据。
$('.more_credits_first').click(function () {
var button = $(this)
var show = $(button).data('show');
console.log(show)
if (show == 'show') {
$.get(window.location.pathname,{}).done(function(data){
$('.tbody.main_credits').append(data.template);
$(button).attr('data-show', 'hide');
$(button).text('Hide');
})
} else {
$(this).attr('data-show', 'show');
$(this).text('More');
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class='more_credits_first' type="button" data-show='show'>Button</button>