admin管理员组文章数量:1025485
I've got a couple of divs which are ordered horizontally and draggable. The inside of each div is always an input + some action buttons. The goal is to allow a user to change the order of the divs via drag and drop. It's working fine in all Browsers except for IE9, which has an issue with dropping the current element to its new position.
When I release the mouse over the div itself, it won't work. But if I release the mouse over a button or input field within the div it's working fine.
See this in action: /
The magic of drag and drop starts at line 181. Try to press the last button with the bullet and drag it over another div. In e.g. Chrome it will work fine, but in IE9 you will need to drop the element over a button or the input field.
HTML
<!-- One div with a input and button inside. The button should initialize the drag -->
<div class="survey-question" draggable="true">
<input type="text" name="q1" value="1" tabindex="1">
<button type="button" title="Drag and drop question" data-action="drag" data-application="survey">●</button>
</div>
JavaScript (the important part)
button.addEventListener("dragstart", dragStart);
button.addEventListener("drop", dragStop);
button.addEventListener("mousemove", handleDragMouseMove);
function dragStart(e) {
this.dragSrcEl = e.target.parentNode;
this.dragSrcElVal = e.target.parentNode.children[0].value;
e.dataTransfer.effectAllowed = "move";
e.dataTransfer.setData("text", e.target.parentNode.innerHTML);
},
function dragDrop(e) {
e.stopPropagation();
if (this.dragSrcEl != e.target.parentNode) {
if (e.target.parentNode.classList.contains("survey-question")) {
this.dragSrcEl.children[0].value = e.target.parentNode.children[0].value;
e.target.parentNode.innerHTML = e.dataTransfer.getData("text");
}
}
return false;
}
function handleDragMouseMove(e) {
if (window.event.button === 1) {
e.target.dragDrop();
}
}
How can I avoid this?
I've got a couple of divs which are ordered horizontally and draggable. The inside of each div is always an input + some action buttons. The goal is to allow a user to change the order of the divs via drag and drop. It's working fine in all Browsers except for IE9, which has an issue with dropping the current element to its new position.
When I release the mouse over the div itself, it won't work. But if I release the mouse over a button or input field within the div it's working fine.
See this in action: http://jsfiddle/aouamurj/
The magic of drag and drop starts at line 181. Try to press the last button with the bullet and drag it over another div. In e.g. Chrome it will work fine, but in IE9 you will need to drop the element over a button or the input field.
HTML
<!-- One div with a input and button inside. The button should initialize the drag -->
<div class="survey-question" draggable="true">
<input type="text" name="q1" value="1" tabindex="1">
<button type="button" title="Drag and drop question" data-action="drag" data-application="survey">●</button>
</div>
JavaScript (the important part)
button.addEventListener("dragstart", dragStart);
button.addEventListener("drop", dragStop);
button.addEventListener("mousemove", handleDragMouseMove);
function dragStart(e) {
this.dragSrcEl = e.target.parentNode;
this.dragSrcElVal = e.target.parentNode.children[0].value;
e.dataTransfer.effectAllowed = "move";
e.dataTransfer.setData("text", e.target.parentNode.innerHTML);
},
function dragDrop(e) {
e.stopPropagation();
if (this.dragSrcEl != e.target.parentNode) {
if (e.target.parentNode.classList.contains("survey-question")) {
this.dragSrcEl.children[0].value = e.target.parentNode.children[0].value;
e.target.parentNode.innerHTML = e.dataTransfer.getData("text");
}
}
return false;
}
function handleDragMouseMove(e) {
if (window.event.button === 1) {
e.target.dragDrop();
}
}
How can I avoid this?
Share Improve this question asked Sep 3, 2014 at 11:46 Andreas RemdtAndreas Remdt 6551 gold badge9 silver badges16 bronze badges 1- No, I didn't. It's a while ago, but I think I sticked to a button solution instead of a div. – Andreas Remdt Commented Nov 28, 2014 at 17:06
1 Answer
Reset to default 4You have to enable Drag and Drop feature to your Browser IE.
Please follow the step to enable Drag and Drop for IE.
- Go to Tools.
- -> Go to Internet Options.
- -> Go to Security tab.
- -> Click on Custom level...
- -> search for Drag and Drop Settings and Click on Enables.
- -> click Ok.
I've got a couple of divs which are ordered horizontally and draggable. The inside of each div is always an input + some action buttons. The goal is to allow a user to change the order of the divs via drag and drop. It's working fine in all Browsers except for IE9, which has an issue with dropping the current element to its new position.
When I release the mouse over the div itself, it won't work. But if I release the mouse over a button or input field within the div it's working fine.
See this in action: /
The magic of drag and drop starts at line 181. Try to press the last button with the bullet and drag it over another div. In e.g. Chrome it will work fine, but in IE9 you will need to drop the element over a button or the input field.
HTML
<!-- One div with a input and button inside. The button should initialize the drag -->
<div class="survey-question" draggable="true">
<input type="text" name="q1" value="1" tabindex="1">
<button type="button" title="Drag and drop question" data-action="drag" data-application="survey">●</button>
</div>
JavaScript (the important part)
button.addEventListener("dragstart", dragStart);
button.addEventListener("drop", dragStop);
button.addEventListener("mousemove", handleDragMouseMove);
function dragStart(e) {
this.dragSrcEl = e.target.parentNode;
this.dragSrcElVal = e.target.parentNode.children[0].value;
e.dataTransfer.effectAllowed = "move";
e.dataTransfer.setData("text", e.target.parentNode.innerHTML);
},
function dragDrop(e) {
e.stopPropagation();
if (this.dragSrcEl != e.target.parentNode) {
if (e.target.parentNode.classList.contains("survey-question")) {
this.dragSrcEl.children[0].value = e.target.parentNode.children[0].value;
e.target.parentNode.innerHTML = e.dataTransfer.getData("text");
}
}
return false;
}
function handleDragMouseMove(e) {
if (window.event.button === 1) {
e.target.dragDrop();
}
}
How can I avoid this?
I've got a couple of divs which are ordered horizontally and draggable. The inside of each div is always an input + some action buttons. The goal is to allow a user to change the order of the divs via drag and drop. It's working fine in all Browsers except for IE9, which has an issue with dropping the current element to its new position.
When I release the mouse over the div itself, it won't work. But if I release the mouse over a button or input field within the div it's working fine.
See this in action: http://jsfiddle/aouamurj/
The magic of drag and drop starts at line 181. Try to press the last button with the bullet and drag it over another div. In e.g. Chrome it will work fine, but in IE9 you will need to drop the element over a button or the input field.
HTML
<!-- One div with a input and button inside. The button should initialize the drag -->
<div class="survey-question" draggable="true">
<input type="text" name="q1" value="1" tabindex="1">
<button type="button" title="Drag and drop question" data-action="drag" data-application="survey">●</button>
</div>
JavaScript (the important part)
button.addEventListener("dragstart", dragStart);
button.addEventListener("drop", dragStop);
button.addEventListener("mousemove", handleDragMouseMove);
function dragStart(e) {
this.dragSrcEl = e.target.parentNode;
this.dragSrcElVal = e.target.parentNode.children[0].value;
e.dataTransfer.effectAllowed = "move";
e.dataTransfer.setData("text", e.target.parentNode.innerHTML);
},
function dragDrop(e) {
e.stopPropagation();
if (this.dragSrcEl != e.target.parentNode) {
if (e.target.parentNode.classList.contains("survey-question")) {
this.dragSrcEl.children[0].value = e.target.parentNode.children[0].value;
e.target.parentNode.innerHTML = e.dataTransfer.getData("text");
}
}
return false;
}
function handleDragMouseMove(e) {
if (window.event.button === 1) {
e.target.dragDrop();
}
}
How can I avoid this?
Share Improve this question asked Sep 3, 2014 at 11:46 Andreas RemdtAndreas Remdt 6551 gold badge9 silver badges16 bronze badges 1- No, I didn't. It's a while ago, but I think I sticked to a button solution instead of a div. – Andreas Remdt Commented Nov 28, 2014 at 17:06
1 Answer
Reset to default 4You have to enable Drag and Drop feature to your Browser IE.
Please follow the step to enable Drag and Drop for IE.
- Go to Tools.
- -> Go to Internet Options.
- -> Go to Security tab.
- -> Click on Custom level...
- -> search for Drag and Drop Settings and Click on Enables.
- -> click Ok.
本文标签: javascriptInternet Explorer 9 Drag and Drop DropEvent not working on div as targetStack Overflow
版权声明:本文标题:javascript - Internet Explorer 9 Drag and Drop: Drop-Event not working on div as target - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745625542a2159836.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论