- 屏幕取词:
a. 代码:
<p>
这是一段简单的段落文本
</p>
<script>
function getWord(){
var word = window.getSelection?
window.getSelection():
document.selection.createRange().text
alert( word )
}
document.body.addEventListener("click", getWord, false)
</script>
b. 效果:
- 移除取词:
a. 代码:
<p>
这是一段简单的段落文本
</p>
<script>
function removeWord(){
window.getSelection?
window.getSelection().removeAllRanges():
document.selection.empty()
}
document.body.addEventListener("click", removeWord, false)
</script>
b. 效果:
|