簡體   English   中英

當用戶在 html 文件中選擇一些文本時,執行 JavaScript function

[英]Execute a JavaScript function when user selects some text in an html file

我有一個顯示一些文本的 html 文件。 當用戶在上面選擇一些文本時,我需要調用 JavaScript function。 我有以下代碼,但highlightSelection() function 永遠不會被調用。

window.onselect = highlightSelection;

function highlightSelection() {

}

當用戶選擇一些文本時,還有其他方法可以調用 JS function 嗎?

您需要將文本放在適當的元素中,例如:

<input type="text" value="This is some selectable text" onselect="showMsg()" />

function showMsg(){

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM