jquery - 每次追加然后更改
问题描述
.append
每次单击按钮时,我都在使用。
$( ".kop_filters" ).append( "<p class='gekozen_datum'>Gekozen datum: </p>" );
如果我单击该按钮 4 次,这将附加在我的页面中,例如:
Gekozen datum:
Gekozen datum:
Gekozen datum:
Gekozen datum:
我希望它出现一次,每次单击它都会删除并再次附加,因此例如在单击它几次后,我将其打印一次。这是因为我想在其中加载一个每次点击都会改变的变量。
编辑:在这里找到解决方案:Ajax 替换而不是追加
解决方案
使用html
方法。
$('button').click(() => {
$(".kop_filters").html((Math.random() * 10).toString())
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="kop_filters"></div>
<button>Update</button>
推荐阅读
- python - spacy 和 train 数据中的 Cased VS uncased BERT 模型
- file - Serilog 未写入从控制台 CORE 3 应用程序中的 appsettings.json 加载的配置的文件
- java - LeetCode 上的 Stock Span 问题是否有更好的解决方案?
- node.js - 使用 Lambda 自动化 NodeJS 应用程序(创建 json 文件)
- flutter - 最佳实践:在 GCF 内调用 Firebase 或在 GCF 之后再调用 Firebase
- c++ - 读取二进制文件直到结束 c++
- c++ - 是否在未初始化的变量上使用复合赋值运算符(+=,...)而不是 C++ 中的 UB?
- visual-studio-code - 尝试在终端中运行 powershell 命令时,F8 或“运行选择”在 VS Code 中不起作用
- elasticsearch - 如何发送json数据弹性搜索获取请求url
- html - 如何使用“位置:绝对”修复 div 底部的页脚?