首页 新闻 会员 周边

js设置div可以拖动之后,div里面的input不能输入

0
悬赏园豆:50 [已解决问题] 解决于 2017-12-18 15:18
大概代码如下:
 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 }
CSS Code
1 <div id="div_add"></div>
2 <div id="log_window" style="width:550px;height:200px;top:123px;left:435px;"></div>
HTML Code
 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>
JS Code

求解决方法,谢谢!

问题补充:

这个是点击一个按钮调用sheild(),弹出一个框,设置这个框可以拖动就出现这个问题。

又是我的主页 又是我 | 初学一级 | 园豆:141
提问于:2017-09-26 16:05
< >
分享
最佳答案
0
本问题的解决方法:根据鼠标点击的标签名判断是否可以拖动。谢谢各位!另外还找到一种不太好的方法,就是给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         };

 



又是我 | 初学一级 |园豆:141 | 2017-09-27 11:48
其他回答(1)
0

亲测可以输入,检查input的html代码 ,检查是否存在html语法错误

收获园豆:50
张泰峰 | 园豆:20 (初学一级) | 2017-09-26 16:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册