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

如何防止拖累孩子,但允許拖累父母?

How do I prevent drag on a child, but allow drag on the parent?(如何防止拖累孩子,但允許拖累父母?)
本文介紹了如何防止拖累孩子,但允許拖累父母?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個用戶可以拖動的 div,在該 div 內是一個跨度,其中包含一些我希望允許用戶選擇的文本(因此他們不能拖動它).如何允許 div 拖動,但不允許 span?

I have a div which the user can drag, inside that div is a span with some text which I want to allow the user to select (thus they cannot drag it). How do I allow the div to drag, but not the span?

dragstart 事件在 div 上.

The dragstart event is on the div.

我可能忽略了一些簡單的事情.我在 div 上嘗試了 draggable=true,在跨度上嘗試了 draggable=false.那沒有用.嘗試在 dragstart 上返回 false,但也沒有用.

I'm probably overlooking something simple. I tried draggable=true on the div, and draggable=false on the span. That didn't work. Tried returning false on dragstart, that didn't work either.

dragstart(大致):

dragstart (roughly):

var jTarget = $(e.target);
if ((jTarget.is('div.header') || (jTarget.parents('div.header')) 
       && !jTarget.is('a, input, span'))) 
{
   e.originalEvent.dataTransfer.setData("Text", "test");
}
else
{
   if(e.preventBubble)
      e.preventBubble();
   if(e.stopPropagation)
      e.stopPropagation();
   return false;//???
}

if else 部分按我的預期工作,但我無法停止拖動并允許選擇.

The if else portion works as I expect, but I cannot get anything to stop the drag and allow the select.

推薦答案

如果你想真正取消拖動并使其不被父拖動處理程序注意到,你需要同時 preventDefaultstopPropagation:

If you want to truly cancel out the drag and make it unnoticeable to parent drag handlers, you need to both preventDefault and stopPropagation:

<div draggable="true" ondragstart="console.log('dragging')">
    <span>Drag me! :)</span>
    <input draggable="true"
           ondragstart="event.preventDefault();
                        event.stopPropagation();"
           value="Don't drag me :(">
</div>

沒有stopPropagation,即使默認行為被阻止(event.defaultPrevented == true),父級ondragstart仍然會被調用).如果您在該處理程序中有不處理這種情況的代碼,您可能會看到一些細微的錯誤.

Without the stopPropagation, the parent ondragstart will still be called even if the default behavior will be prevented (event.defaultPrevented == true). If you have code in that handler that doesn't handle this case, you may see subtle bugs.

當然你也可以把上面的 JavaScript 放到 element.addEventListener('dragstart', ...) 里面.

You can of course put the JavaScript above inside element.addEventListener('dragstart', ...) too.

這篇關于如何防止拖累孩子,但允許拖累父母?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 如何監視函數中的函數調用?)
主站蜘蛛池模板: 中文字幕欧美一区 | 欧洲av在线 | 91久久久久久 | 日韩一区二区在线观看 | 亚洲精品www | 成年人在线视频 | 精品久久久久久久久久久久 | 久久综合伊人 | 福利社午夜影院 | 久久亚洲欧美日韩精品专区 | 欧美一级片在线观看 | 中文字幕高清视频 | 亚洲视频免费观看 | 欧美黄在线观看 | 成人亚洲| 成人精品国产一区二区4080 | 看亚洲a级一级毛片 | 亚洲综合大片69999 | 99re在线视频免费观看 | 免费观看黄色一级片 | 中文字幕综合在线 | 精品中文字幕一区二区三区 | 国产精品久久久久aaaa樱花 | 成年人网站免费视频 | 久久精品国产亚洲 | 81精品国产乱码久久久久久 | 在线视频一区二区三区 | 久久日本 | 国产小视频在线观看 | 日韩欧美一级片 | 高清视频一区二区三区 | 久久久久久综合 | 欧美成年网站 | 国产精品爱久久久久久久 | 麻豆天堂 | 久久四虎| 免费看黄视频网站 | 综合精品 | 桃色五月 | 欧美日韩一区在线播放 | 国产精品亚洲精品 |