Bug570_CaiShuHuang #170

Merged
mrlan merged 7 commits from Bug570_CaiShuHuang into Alpha-snapshot20240618 2024-08-27 08:18:45 +08:00
2 changed files with 41 additions and 1 deletions

View File

@ -196,4 +196,40 @@ function exportToCSV() {
link.click(); link.click();
document.body.removeChild(link); document.body.removeChild(link);
} }
/**
*
* 随机选取 10 个单词学习
*/
function random_select_word(word) {
alert("点击熟悉与不熟悉之后,单词自动返回生词库")
// 获取所有带有 "word-container" 类的 <p> 标签
const container = document.querySelector('.word-container');
console.log("container",container)
// 获取所有带有"new-word"类的<p>标签
let wordContainers = container.querySelectorAll('.new-word');
// 检查是否存在带有"new-word"类的<p>标签
if (wordContainers.length > 0) {
// 将NodeList转换为数组
let wordContainersArray = [...wordContainers];
// 随机打乱数组,乱序
for (let i = wordContainersArray.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[wordContainersArray[i], wordContainersArray[j]] = [wordContainersArray[j], wordContainersArray[i]];
}
wordContainersArray.forEach((p, index) => {
if (index < 10) {
p.style.display = 'block';
} else {
p.style.display = 'none';
}
});
}
}

View File

@ -146,11 +146,15 @@
{% if d_len > 0 %} {% if d_len > 0 %}
<p> <p>
<b>我的生词簿</b> <b>我的生词簿</b>
<label for="move_dynamiclly"> <label for="move_dynamiclly">
<input type="checkbox" name="move_dynamiclly" id="move_dynamiclly" checked> <input type="checkbox" name="move_dynamiclly" id="move_dynamiclly" checked>
允许动态调整顺序 允许动态调整顺序
</label> </label>
<br>
<a class="btn btn-primary btn-lg" onclick="random_select_word('{{ word }}')" role="button">随机选取10个</a>
<a class="btn btn-primary btn-lg" onclick="location.reload();" role="button">显示所有生词</a>
</p> </p>
<!--添加导出按钮--> <!--添加导出按钮-->
<button class="btn btn-primary" onclick="exportToCSV()">导出</button> <button class="btn btn-primary" onclick="exportToCSV()">导出</button>