下面这段js为什么加了<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">这个协议在火狐下运行不了去掉了那句话,在IE下是好的,但在火狐下不能拖动! 本人是刚接触js,求高手指教,最好帮忙修改一下,加一点注释!另外追加分,小弟在这拜谢了!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MyHtml.html</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style>
/**
* 弹出层css
*/
.pop {
width: 80%;
border: 1px #96D1DF solid;
background: #fff;
padding: 1px;
color: #333;
position: absolute;
top: 15%;
left: 15%;
height: auto;
z-index: 10
}
/**
* 弹出层css
*/
.pop_ {
width: 80%;
border: 1px #96D1DF solid;
background: #fff;
padding: 1px;
color: #333;
position: absolute;
top: 15%;
left: 15%;
height: auto;
z-index: 10
}
.pop_title {
float: left;
width: 100%;
height: 30px;
line-height: 30px;
/* background: #ecf9ff url ('../images/title_move.gif') center no-repeat; */
background: #ecf9ff;
border-bottom: 1px #d3ecf3 solid;
color: #444;
font-weight: bold
}
.pop_title_left {
float: left;
width: 90%;
overflow: hidden;
text-indent: 6px;
cursor: move
}
.pop_title_left img {
float: left;
border: 0;
margin: 10px 0 0 5px
}
.pop_title_right {
width: 5%;
float: right;
text-align: right;
cursor: pointer
}
.pop_title_right_print {
width: 3%;
float: left;
text-align: right
}
.pop_title_right img {
margin: 5px 10px 5px 10px;
cursor: pointer
}
.pop_title_right_print img {
margin: 5px 10px 5px 10px;
cursor: pointer
}
.pop_content {
float: left;
width: 100%;
margin: 1px 0 0 0;
font-size: 14px
}
.pop_function {
float: left;
width: 100%;
height: 30px;
line-height: 30px;
border-top: 1px #fff solid;
text-align: center
}
.pop_search {
width: 100%;
height: 35px;
border-top: 1px #fff solid;
text-align: center;
font-size: 12px;
font-weight: bold;
margin: 5px 0 5px 0;
border-bottom: 3px #96D1DF dotted;
}
.pop_page {
width: 100%;
height: 25px;
text-align: center;
font-size: 12px;
border-top: 3px #96D1DF dotted;
vertical-align: middle;
}
</style>
<script type="text/javascript">
function getxy(e) {
var a = new Array();
var t = e.offsetTop;
var l = e.offsetLeft;
var w = e.offsetWidth;
var h = e.offsetHeight;
while (e = e.offsetParent) {
t += e.offsetTop;
l += e.offsetLeft;
}
a[0] = t;
a[1] = l;
a[2] = w;
a[3] = h;
return a;
}
//----------------------------------
var DragForAll = {};
function _enableDragForAll(e, toMoveObj, obj2, obj3) {
if (DragForAll.o) {
return false;
}
var clickObj = document.getElementById(toMoveObj);
if (!clickObj) {
return;
}
DragForAll.o = clickObj;
if (document.getElementById(obj2)) {
DragForAll.p = document.getElementById(obj2);
}
DragForAll.xy = getxy(DragForAll.o);
e = e || event;
if (!clickObj.style.left) {
DragForAll.xx = new Array((e.x - DragForAll.xy[1]), (e.y - DragForAll.xy[0]));
} else {
DragForAll.xgap = parseInt(clickObj.style.left.substring(0, clickObj.style.left.indexOf("px")));
DragForAll.ygap = parseInt(clickObj.style.top.substring(0, clickObj.style.top.indexOf("px")));
DragForAll.xx = new Array((e.x - DragForAll.xgap), (e.y - DragForAll.ygap));
DragForAll.xgap -= DragForAll.xy[1];
DragForAll.ygap -= DragForAll.xy[0];
}
DragForAll.fitToCont = obj3;
if (obj3) {
DragForAll.fitArea = getxy(DragForAll.fitToCont);
}
return false;
}
function _DragObjForAll(e) {
if (!DragForAll.o) {
return;
}
e = e || event;
var old_left = e.x - DragForAll.xx[0];
var old_top = e.y - DragForAll.xx[1];
if (DragForAll.fitToCont) {
if ((old_left - DragForAll.xgap) - DragForAll.fitArea[1] <= 0 || old_top - DragForAll.ygap - DragForAll.fitArea[0] <= 0) {
return;
}
if (old_left - DragForAll.xgap + DragForAll.xy[2] >= DragForAll.fitArea[1] + DragForAll.fitArea[2] || old_top - DragForAll.ygap + DragForAll.xy[3] >= DragForAll.fitArea[0] + DragForAll.fitArea[3]) {
return;
}
}
DragForAll.o.style.left = old_left + "px";
DragForAll.o.style.top = old_top + "px";
if (DragForAll.p) {
DragForAll.p.style.left = (old_left + 5) + "px";
DragForAll.p.style.top = (old_top + 5) + "px";
}
}
function _releaseDragObjForAll(e) {
DragForAll = {};
}
document.onmousemove = function (e) {
_DragObjForAll(e);
};
document.onmouseup=function(e){
_releaseDragObjForAll(e);
e=e||event;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id ="mm">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<input type="button" value="付款" onclick="xingZQYTree.style.display='';xingZQYTree.style.top=event.clientY;xingZQYTree.style.left=event.clientX" /> <div id="xingZQYTree" class="pop"
style="display: none; width: 400px; overflow: auto; position: absolute; background-color: #FFFFFF; border: 1px solid #0099CC; padding-left: 0px">
<div id="pop_title" class="pop_title"
onmousedown="_enableDragForAll(event,'xingZQYTree');" title='按住鼠标可随意拖动此窗口'>
<div class="pop_title_left" style="font-size: 14px">
退款单
</div>
<div class="pop_title_right">
<label title="关闭此窗口" onclick="xingZQYTree.style.display='none';">
X
</label>
</div>
</div>
<div class="pop_content">
<table>
<tr>
<td> <asp:Label ID="Label1" runat="server" Text="收款人:"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="center">
<asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click"/></td>
</tr>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MyHtml.html</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style>
/**
* 弹出层css
*/
.pop {
width: 80%;
border: 1px #96D1DF solid;
background: #fff;
padding: 1px;
color: #333;
position: absolute;
top: 15%;
left: 15%;
height: auto;
z-index: 10
}
/**
* 弹出层css
*/
.pop_ {
width: 80%;
border: 1px #96D1DF solid;
background: #fff;
padding: 1px;
color: #333;
position: absolute;
top: 15%;
left: 15%;
height: auto;
z-index: 10
}
.pop_title {
float: left;
width: 100%;
height: 30px;
line-height: 30px;
/* background: #ecf9ff url ('../images/title_move.gif') center no-repeat; */
background: #ecf9ff;
border-bottom: 1px #d3ecf3 solid;
color: #444;
font-weight: bold
}
.pop_title_left {
float: left;
width: 90%;
overflow: hidden;
text-indent: 6px;
cursor: move
}
.pop_title_left img {
float: left;
border: 0;
margin: 10px 0 0 5px
}
.pop_title_right {
width: 5%;
float: right;
text-align: right;
cursor: pointer
}
.pop_title_right_print {
width: 3%;
float: left;
text-align: right
}
.pop_title_right img {
margin: 5px 10px 5px 10px;
cursor: pointer
}
.pop_title_right_print img {
margin: 5px 10px 5px 10px;
cursor: pointer
}
.pop_content {
float: left;
width: 100%;
margin: 1px 0 0 0;
font-size: 14px
}
.pop_function {
float: left;
width: 100%;
height: 30px;
line-height: 30px;
border-top: 1px #fff solid;
text-align: center
}
.pop_search {
width: 100%;
height: 35px;
border-top: 1px #fff solid;
text-align: center;
font-size: 12px;
font-weight: bold;
margin: 5px 0 5px 0;
border-bottom: 3px #96D1DF dotted;
}
.pop_page {
width: 100%;
height: 25px;
text-align: center;
font-size: 12px;
border-top: 3px #96D1DF dotted;
vertical-align: middle;
}
</style>
<script type="text/javascript">
function getxy(e) {
var a = new Array();
var t = e.offsetTop;
var l = e.offsetLeft;
var w = e.offsetWidth;
var h = e.offsetHeight;
while (e = e.offsetParent) {
t += e.offsetTop;
l += e.offsetLeft;
}
a[0] = t;
a[1] = l;
a[2] = w;
a[3] = h;
return a;
}
//----------------------------------
var DragForAll = {};
function _enableDragForAll(e, toMoveObj, obj2, obj3) {
if (DragForAll.o) {
return false;
}
var clickObj = document.getElementById(toMoveObj);
if (!clickObj) {
return;
}
DragForAll.o = clickObj;
if (document.getElementById(obj2)) {
DragForAll.p = document.getElementById(obj2);
}
DragForAll.xy = getxy(DragForAll.o);
e = e || event;
if (!clickObj.style.left) {
DragForAll.xx = new Array((e.x - DragForAll.xy[1]), (e.y - DragForAll.xy[0]));
} else {
DragForAll.xgap = parseInt(clickObj.style.left.substring(0, clickObj.style.left.indexOf("px")));
DragForAll.ygap = parseInt(clickObj.style.top.substring(0, clickObj.style.top.indexOf("px")));
DragForAll.xx = new Array((e.x - DragForAll.xgap), (e.y - DragForAll.ygap));
DragForAll.xgap -= DragForAll.xy[1];
DragForAll.ygap -= DragForAll.xy[0];
}
DragForAll.fitToCont = obj3;
if (obj3) {
DragForAll.fitArea = getxy(DragForAll.fitToCont);
}
return false;
}
function _DragObjForAll(e) {
if (!DragForAll.o) {
return;
}
e = e || event;
var old_left = e.x - DragForAll.xx[0];
var old_top = e.y - DragForAll.xx[1];
if (DragForAll.fitToCont) {
if ((old_left - DragForAll.xgap) - DragForAll.fitArea[1] <= 0 || old_top - DragForAll.ygap - DragForAll.fitArea[0] <= 0) {
return;
}
if (old_left - DragForAll.xgap + DragForAll.xy[2] >= DragForAll.fitArea[1] + DragForAll.fitArea[2] || old_top - DragForAll.ygap + DragForAll.xy[3] >= DragForAll.fitArea[0] + DragForAll.fitArea[3]) {
return;
}
}
DragForAll.o.style.left = old_left + "px";
DragForAll.o.style.top = old_top + "px";
if (DragForAll.p) {
DragForAll.p.style.left = (old_left + 5) + "px";
DragForAll.p.style.top = (old_top + 5) + "px";
}
}
function _releaseDragObjForAll(e) {
DragForAll = {};
}
document.onmousemove = function (e) {
_DragObjForAll(e);
};
document.onmouseup=function(e){
_releaseDragObjForAll(e);
e=e||event;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id ="mm">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<input type="button" value="付款" onclick="xingZQYTree.style.display='';xingZQYTree.style.top=event.clientY;xingZQYTree.style.left=event.clientX" /> <div id="xingZQYTree" class="pop"
style="display: none; width: 400px; overflow: auto; position: absolute; background-color: #FFFFFF; border: 1px solid #0099CC; padding-left: 0px">
<div id="pop_title" class="pop_title"
onmousedown="_enableDragForAll(event,'xingZQYTree');" title='按住鼠标可随意拖动此窗口'>
<div class="pop_title_left" style="font-size: 14px">
退款单
</div>
<div class="pop_title_right">
<label title="关闭此窗口" onclick="xingZQYTree.style.display='none';">
X
</label>
</div>
</div>
<div class="pop_content">
<table>
<tr>
<td> <asp:Label ID="Label1" runat="server" Text="收款人:"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="center">
<asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click"/></td>
</tr>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
解决方案 »
- 看看这js代码,帮忙改一下
- gridpanel中无法删除多行
- 日期控件
- 简单Asp采集、仿站(主要是些表格、类似于新闻发布)RMB[速联系、在线等
- 透明的图片
- 如何在点击一个链接以后,显示一个层,这个层的左边为链接的第一个文字位置,顶部为链接的底部?
- 向各位请教在javascript中,$这个符号的用法和作用
- 这个select如何设置初始选中
- 如果将window.open打开的页隐藏。在线等.............
- 我将提供一个简短的,快餐式的关于JavaScript的入门读物给大家
- Ext combox listeners为什么总是显示第一值
- Jquery如何取数组里的值?[顺便祝大家元旦快乐!]
<head>
<title>MyHtml.html</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style>
/**
* 弹出层css
*/
.pop {
width: 80%;
border: 1px #96D1DF solid;
background: #fff;
padding: 1px;
color: #333;
position: absolute;
top: 15%;
left: 15%;
height: auto;
z-index: 10
}/**
* 弹出层css
*/
.pop_ {
width: 80%;
border: 1px #96D1DF solid;
background: #fff;
padding: 1px;
color: #333;
position: absolute;
top: 15%;
left: 15%;
height: auto;
z-index: 10
}.pop_title {
float: left;
width: 100%;
height: 30px;
line-height: 30px;
/* background: #ecf9ff url ('../images/title_move.gif') center no-repeat; */
background: #ecf9ff;
border-bottom: 1px #d3ecf3 solid;
color: #444;
font-weight: bold
}.pop_title_left {
float: left;
width: 90%;
overflow: hidden;
text-indent: 6px;
cursor: move
}.pop_title_left img {
float: left;
border: 0;
margin: 10px 0 0 5px
}.pop_title_right {
width: 5%;
float: right;
text-align: right;
cursor: pointer
}.pop_title_right_print {
width: 3%;
float: left;
text-align: right
}.pop_title_right img {
margin: 5px 10px 5px 10px;
cursor: pointer
}.pop_title_right_print img {
margin: 5px 10px 5px 10px;
cursor: pointer
}.pop_content {
float: left;
width: 100%;
margin: 1px 0 0 0;
font-size: 14px
}.pop_function {
float: left;
width: 100%;
height: 30px;
line-height: 30px;
border-top: 1px #fff solid;
text-align: center
}.pop_search {
width: 100%;
height: 35px;
border-top: 1px #fff solid;
text-align: center;
font-size: 12px;
font-weight: bold;
margin: 5px 0 5px 0;
border-bottom: 3px #96D1DF dotted;
}.pop_page {
width: 100%;
height: 25px;
text-align: center;
font-size: 12px;
border-top: 3px #96D1DF dotted;
vertical-align: middle;
}
</style>
<script type="text/javascript">
function getxy(e) {
var a = new Array();
var t = e.offsetTop;
var l = e.offsetLeft;
var w = e.offsetWidth;
var h = e.offsetHeight;
while (e = e.offsetParent) {
t += e.offsetTop;
l += e.offsetLeft;
}
a[0] = t;
a[1] = l;
a[2] = w;
a[3] = h;
return a;
}
//----------------------------------
var DragForAll = {};
function _enableDragForAll(e, toMoveObj, obj2, obj3) {
if (DragForAll.o) {
return false;
}
var clickObj = document.getElementById(toMoveObj);
if (!clickObj) {
return;
}
DragForAll.o = clickObj;
if (document.getElementById(obj2)) {
DragForAll.p = document.getElementById(obj2);
}
DragForAll.xy = getxy(DragForAll.o);
e = e || event;
if (!clickObj.style.left) {//===================
DragForAll.xx = new Array((e.clientX - DragForAll.xy[1]), (e.clientY - DragForAll.xy[0]));
} else {
DragForAll.xgap = parseInt(clickObj.style.left.substring(0, clickObj.style.left.indexOf("px")));
DragForAll.ygap = parseInt(clickObj.style.top.substring(0, clickObj.style.top.indexOf("px")));
//===================
DragForAll.xx = new Array((e.clientX - DragForAll.xgap), (e.clientY - DragForAll.ygap));
DragForAll.xgap -= DragForAll.xy[1];
DragForAll.ygap -= DragForAll.xy[0];
}
DragForAll.fitToCont = obj3;
if (obj3) {
DragForAll.fitArea = getxy(DragForAll.fitToCont);
}
return false;
}
function _DragObjForAll(e) {
if (!DragForAll.o) {
return;
}
e = e || event;//===================
var old_left = e.clientX - DragForAll.xx[0];
var old_top = e.clientY - DragForAll.xx[1];
if (DragForAll.fitToCont) {
if ((old_left - DragForAll.xgap) - DragForAll.fitArea[1] <= 0 || old_top - DragForAll.ygap - DragForAll.fitArea[0] <= 0) {
return;
}
if (old_left - DragForAll.xgap + DragForAll.xy[2] >= DragForAll.fitArea[1] + DragForAll.fitArea[2] || old_top - DragForAll.ygap + DragForAll.xy[3] >= DragForAll.fitArea[0] + DragForAll.fitArea[3]) {
return;
}
};
DragForAll.o.style.left = old_left + "px";
DragForAll.o.style.top = old_top + "px";
if (DragForAll.p) {
DragForAll.p.style.left = (old_left + 5) + "px";
DragForAll.p.style.top = (old_top + 5) + "px";
}
}
function _releaseDragObjForAll(e) {
DragForAll = {};
}
document.onmousemove = function (e) {
_DragObjForAll(e);
};
document.onmouseup = function (e) {
_releaseDragObjForAll(e);
e = e || event;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id ="mm">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<input type="button" value="付款" onclick="document.getElementById('xingZQYTree').style.display='';document.getElementById('xingZQYTree').style.top=event.clientY+'px';document.getElementById('xingZQYTree').style.left=event.clientX+'px';" /><div id="xingZQYTree" class="pop"
style="display: none; width: 400px; overflow: auto; position: absolute; background-color: #FFFFFF; border: 1px solid #0099CC; padding-left: 0px">
<!--------------------这里----------->
<div id="pop_title" class="pop_title"
onmousedown="_enableDragForAll(event,'xingZQYTree');" title='按住鼠标可随意拖动此窗口'>
<div class="pop_title_left" style="font-size: 14px">
退款单
</div>
<div class="pop_title_right"><!--------------------这里----------->
<label title="关闭此窗口" onclick="document.getElementById('xingZQYTree').style.display='none';">
X
</label>
</div>
</div>
<div class="pop_content">
<table>
<tr>
<td> <asp:Label ID="Label1" runat="server" Text="收款人:"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="center">
<asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click"/></td>
</tr>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13那里面不能拖动哦
http://www.code-design.cn/eg/drag.html