diff --git a/app/static/js/word_operation.js b/app/static/js/word_operation.js index 6413971..ddde6a2 100644 --- a/app/static/js/word_operation.js +++ b/app/static/js/word_operation.js @@ -196,4 +196,40 @@ function exportToCSV() { link.click(); document.body.removeChild(link); -} \ No newline at end of file +} + +/** + * + * 随机选取 10 个单词学习 + */ +function random_select_word(word) { + + alert("点击熟悉与不熟悉之后,单词自动返回生词库") + // 获取所有带有 "word-container" 类的

标签 + const container = document.querySelector('.word-container'); + + console.log("container",container) + + // 获取所有带有"new-word"类的

标签 + let wordContainers = container.querySelectorAll('.new-word'); + + // 检查是否存在带有"new-word"类的

标签 + 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'; + } + }); + } +} diff --git a/app/templates/userpage_get.html b/app/templates/userpage_get.html index abb5632..8daa344 100644 --- a/app/templates/userpage_get.html +++ b/app/templates/userpage_get.html @@ -146,11 +146,15 @@ {% if d_len > 0 %}

+ 我的生词簿 +
+ 随机选取10个 + 显示所有生词