[英]Detect when text is entered into the textarea and change it correspondingly
[英]Detect when user selects text in a textarea
如何檢測用戶何時使用JS在textarea中選擇文本? 我使用了jQuery-fieldselection,但只有將range.text
放入pre標簽時它才有效。它不適用於div。
使用select
事件。 它適用於所有主流瀏覽器中的<textarea>
和<input type="text">
元素。 對其他要素的支持並不普遍。
document.getElementById("your_textarea").onselect = function() {
alert("Select");
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.