1 #div_add { 2 HEIGHT: 796px; 3 WIDTH: 1420px; 4 background-color:#000; 5 position:absolute; 6 top:0; 7 left:0; 8 z-index:2; 9 opacity:0.1; 10 filter: alpha(opacity=10); 11 display:none; 12 } 13 #log_window { 14 BORDER-LEFT-WIDTH: 1px; 15 CURSOR: default; 16 FONT-SIZE: 9pt; 17 HEIGHT: 200px; 18 BORDER-RIGHT-WIDTH: 1px; 19 WIDTH: 550px; 20 BORDER-BOTTOM-WIDTH: 1px; 21 POSITION: absolute; 22 LEFT: 435px; 23 Z-INDEX: 10002; 24 TOP: 123px; 25 BORDER-TOP-WIDTH: 1px; 26 display:none; 27 background-color:#ffffff; 28 }
1 <div id="div_add"></div> 2 <div id="log_window" style="width:550px;height:200px;top:123px;left:435px;"></div>
1 <script> 2 function sheild(){ 3 var html=''; 4 html+='<input id="ipt_qty" value="" type= "text" />'; 5 $('#log_window').html(html); 6 } 7 8 //下面是设置div可以拖动,屏蔽之后输入框可以输入 9 var o,X, Y; 10 function getObject(obj, e) { 11 o = obj; 12 document.all ? o.setCapture() : window.captureEvents(Event.MOUSEMOVE); 13 X = e.clientX - parseInt(o.style.left); 14 Y = e.clientY - parseInt(o.style.top); 15 } 16 document.getElementById("log_window").onmousedown = function (e) { 17 getObject(this, e || event); 18 }; 19 document.onmousemove = function (dis) { 20 if (!o) { 21 return; 22 } 23 if (!dis) { 24 dis = event; 25 } 26 o.style.left = dis.clientX - X + "px"; 27 o.style.top = dis.clientY - Y + "px"; 28 }; 29 document.onmouseup = function () { 30 if (!o) { 31 return; 32 } 33 document.all ? o.releaseCapture() : window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP) 34 o = ''; 35 }; 36 </script>
求解决方法,谢谢!
本问题的解决方法:根据鼠标点击的标签名判断是否可以拖动。谢谢各位!另外还找到一种不太好的方法,就是给input加上一个默认的焦点,即使用$(input).focus(),有用但,不够灵活。
1 document.getElementById("log_window").onmousedown = function (e) { 2 2 var obj = document.elementFromPoint(event.clientX, event.clientY); 3 3 if (obj.tagName.toLowerCase() === 'input') { 4 4 return false; 5 5 } 6 6 getObject(this, e || event); 7 7 };
亲测可以输入,检查input的html代码 ,检查是否存在html语法错误