更多操作
Xp00000000(留言 | 贡献) 小无编辑摘要 |
Xp00000000(留言 | 贡献) 小无编辑摘要 |
||
第69行: | 第69行: | ||
<html> | <html> | ||
<script> | <script> | ||
function | function cycleTextData(element) { | ||
const states = JSON.parse(element.dataset.states || '["A", "B", "C"]'); | |||
const states = JSON.parse(element.dataset.states); | const currentIndex = parseInt(element.dataset.current || 0); | ||
const | const nextIndex = (currentIndex + 1) % states.length; | ||
element.textContent = | element.textContent = states[nextIndex]; | ||
element.dataset.current = nextIndex; | element.dataset.current = nextIndex; | ||
// | // 检测当前文本(方法1) | ||
console.log("当前文本(方法1):", element.textContent); | |||
// 检测当前文本(方法2) | |||
const currentText = states[nextIndex]; | |||
console.log("当前文本(方法2):", currentText); | |||
} | } | ||
function | // 示例:通过按钮检测当前文本 | ||
const | function checkCurrentText() { | ||
const element = document.querySelector('div[data-states]'); | |||
alert("当前显示的文本是: " + element.textContent); | |||
} | } | ||
</script> | </script> | ||
<div onclick="cycleTextData(this)" data-states='["EZ 1", "HD 6", "IN 9"]' | |||
data-current="0" style="cursor:pointer;"> | |||
EZ 1 | |||
</div> | |||
<button onclick="checkCurrentText()">检测当前文本</button> | |||
</html> | </html> |
2025年7月5日 (六) 10:02的版本
EZ 1
| |
4:3
|
abc |
EZ 1
| |
4:3
|
a_ccc_1234.png |
EZ 1