久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 JavaScript 暫時禁用文本選擇?

How can I disable Text Selection temporarily using JavaScript?(如何使用 JavaScript 暫時禁用文本選擇?)
本文介紹了如何使用 JavaScript 暫時禁用文本選擇?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

這是一個有點具體的問題,所以我會直奔主題.

this is a bit of a specific question so I'll get right to the point.

我正在為 Web 應用程序的一部分開發一個簡短而簡單的拖放例程,盡管拖放位工作正常,但該站點在操作過程中變得非常丑陋,因為瀏覽器仍然執行默認設置操作和文本選擇.

I'm working on a short and simple drag and drop routine for part of a web application, and although the dragging and dropping bit works fine, the site goes all ugly-tastic during the operation because the browser still does the default operation and works on text selecting.

我嘗試了一些解決方案,主要涉及從 mousedown 或 click 事件返回 false,雖然它們在某些瀏覽器中禁用了文本選擇,但它們似乎也完全禁用了 mouseup 事件,破壞了腳本的drop"位并讓這個永久浮動圖標懸在鼠標周圍——不好玩.

I've tried a few solutions mainly involving returning false from the mousedown or click events, and although they disable text selection in some browsers, they also seem to disable the mouseup event entirely, ruining the "drop" bit of the script and leaving this perma-floating icon hanging around the mouse-- not fun.

我真的不希望文本選擇完全消失,我只是想建議瀏覽器...不要在拖動時這樣做,如果這有意義的話.由于我知道受影響的區域(涉及 iframe),因此我可以輕松地將屬性應用于受影響的元素等.如有必要,我可以發布代碼,但我正在尋找更多通用解決方案.由于這只是美學問題,我正在尋找適用于大多數瀏覽器的修復程序,它并不是那么重要.

I don't really want text selection to be gone entirely, I just want to suggest that the browser... not do it while dragging, if that makes sense. Since I know the area that is affected (there are iframes involved) I can easily apply a property to the affected elements, etc. I can post code if necessary, but I'm looking for more of a general solution. Since this is an aesthetics thing only, I'm looking for a fix that works in most browsers, it's not really that crucial.

謝謝!

推薦答案

在 W3C 瀏覽器中,您可以在 event 對象上調用 preventDefault 方法.IE 等效項是將 returnValue 設置為 false.

In W3C browsers, you can call the preventDefault method on the event object. The IE equivalent is to set the returnValue to false.

function stopDefault(e) {
    if (e && e.preventDefault) {
        e.preventDefault();
    }
    else {
        window.event.returnValue = false;
    }
    return false;
}

只需重新閱讀問題,您可能還希望在處理實際拖動的代碼部分中阻止默認操作,而不僅僅是在初始鼠標按下或單擊時.

Just re-read the question and you might also want to prevent the default action in the part of your code that handles the actual dragging, and not just at the initial mousedown or click.

這篇關于如何使用 JavaScript 暫時禁用文本選擇?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 99re视频在线观看 | 国产一区91精品张津瑜 | 中文字幕亚洲区 | 国产精品99999999 | 精品日韩一区二区 | 国产精品91视频 | 欧美一级片在线看 | 自拍中文字幕 | 日韩精品一区二区三区在线播放 | 日韩欧美二区 | 美女天天操| 免费在线色 | 亚洲成网站 | 欧美高清视频一区 | 一级片视频免费观看 | 久久久久久久久久久久久久国产 | 日本三级电影在线观看视频 | 黑人精品 | 日韩在线免费视频 | 久久精品91 | 久久久久久久久一区 | 亚洲区一 | 成人在线观看免费 | 亚洲一区免费视频 | 91精品国产色综合久久不卡蜜臀 | 欧美视频第二页 | 亚洲成人精选 | 国产综合久久 | 成人精品视频99在线观看免费 | 久久国产麻豆 | 犬夜叉在线观看 | 亚洲成人精品国产 | 国产欧美在线一区 | 久久久99精品免费观看 | 日本韩国电影免费观看 | 日本亚洲精品 | 欧美福利| 久久日韩粉嫩一区二区三区 | 欧美色偷拍 | 精品久久香蕉国产线看观看亚洲 | 国产精品96久久久久久 |