javascript拖动div代码将冻结输入文本
我使用这段代码拖动一个DIV,它是一个小信息框。 在其中,我有一些简单的HTML,包括输入文本或类似的内容。启用拖动时(请参见代码),所有输入都将冻结javascript拖动div代码将冻结输入文本,javascript,Javascript,我使用这段代码拖动一个DIV,它是一个小信息框。 在其中,我有一些简单的HTML,包括输入文本或类似的内容。启用拖动时(请参见代码),所有输入都将冻结 var selected = null, // Object of the element to be moved x_pos = 0, y_pos = 0, // Stores x & y coordinates of the mouse pointer x_elem = 0, y_elem = 0; // Stores
var selected = null, // Object of the element to be moved
x_pos = 0, y_pos = 0, // Stores x & y coordinates of the mouse pointer
x_elem = 0, y_elem = 0; // Stores top, left values (edge) of the element
// Will be called when user starts dragging an element
function _drag_init(elem) {
// Store the object of the element which needs to be moved
selected = elem;
x_elem = x_pos - selected.offsetLeft;
y_elem = y_pos - selected.offsetTop;
}
// Will be called when user dragging an element
function _move_elem(e) {
x_pos = document.all ? window.event.clientX : e.pageX;
y_pos = document.all ? window.event.clientY : e.pageY;
if (selected !== null) {
selected.style.left = (x_pos - x_elem) + 'px';
selected.style.top = (y_pos - y_elem) + 'px';
}
}
// Destroy the object when we are done
function _destroy() {
selected = null;
}
document.onmousemove = _move_elem;
document.onmouseup = _destroy;
这里有一个更大的代码,因此我将简化:
div = document.getElementById("mydiv");
div.onmousedown = function () {
_drag_init(this);
return false;
};
现在,当我显示DIV时,拖动工作平稳(FF 53),但其中的任何输入元素都被冻结:)
我的信息盒(DIV)的内容很简单
<input id="input_text" type="text" name="product" list="productName"/>
<datalist id="productName">
<option value="Pen">Pen</option>
<option value="Pencil">Pencil</option>
<option value="Paper">Paper</option>
</datalist><br> <button id="myNiceButton" action="input_text">OK</button>
笔
铅笔
纸类
嗯
我已经尝试了StackOverflow的一系列解决方案,但都没有成功,包括这个
内部可拖动(固定)
但这些事件似乎根本没有被触发。也尝试了draggable=“false”,但同样的故事,不起作用
有什么问题吗?实际上,拖动代码很好
div.onmousedown = function () {
_drag_init(this);
return false; // <-- remove this
};
div.onmousedown=函数(){
_拖动_init(此);
返回false//
div.onmousedown = function () {
_drag_init(this);
return false; // <-- remove this
};