Дми*_*рук 2 html javascript ajax jquery dom
我发出一个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');
}
})Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33 次 |
| 最近记录: |