现在是alert("lin");这段代码都实现不了~~~~~~~~~
解决方案 »
- 在javascript中如何启动和关闭一个进程?
- jqgrid 添加
- 怎么通过鼠标点击借助javaScript的来获得页面中的当前dom元素信息(类似firebug或ie Developer这样的功能)
- 有没有能够一次显示几个月,并且能一次点选几个日期的日历控件
- 发一下js文件源码,请教其中的一行代码,谢谢。
- FireFox 1.0.7 中文版 和 FireFox 1.0.7 中文增强版 有啥区别???
- 初学者请教有关各文档对象模型的生命周期问题
- 我要在JavaScript中控制.Net中的Radionbutton的变化:选中其中的一个RadioButton,其它都变成radiobutton.check=false,怎么做?在线等,有
- 菜鸟问题:JScript怎样记录点击某个按钮的次数?比如点击5次后Alert"5次"?
- JS中数据类型的转换一问
- Ext 2.1 中 IE 调用init函数问题
- 正则删除一段script脚本
请贴出调用onmouseup事件的代码段PS:楼主该结一些帖子了
<title>测试可动div</title>
<script language='javascript' type='text/javascript'>
function down(mevent,id)
{
var ev=mevent;
var bool=false;
if(document.all&&ev.button==1)
{
bool=true;
}
else
{
if(ev.button==0)
{
bool=true;
}
}
if(bool==true)
{ var div=window.document.getElementById(id);
div.onmouseup=up;
var x=parseInt(ev.clientX-div.offsetLeft);
var y=parseInt(ev.clientY-div.offsetTop);
window.document.documentElement.onmousemove=function(mEvent)
{
if(document.all)
{
div.style.left=(ev.clientX-x)+"px";
div.style.top=(ev.clientY-y)+"px";
}
else
{
div.style.left=(mEvent.clientX-x)+"px";
div.style.top=(mEvent.clientY-y)+"px";
}
}
}
}function up()
{
window.document.documentElement.onmousemove=null;
}
</script>
</head>
<body>
<div id="oDiv" onmousedown="down(event,'oDiv')" style="cursor:move;position:absolute;width:100px;height:60px;border:1px solidsilver;left:100px;top:100px;z-index:9999;"></div>
</body></html>我把代码复制到一个新页面中,功能正常~~~~可就是在我要使用的那个页面~~~出异常
^^,可以供参考下。
{
var ev=mevent;
var bool=false;
if(document.all&&ev.button==1)
{
bool=true;
}
else
{
if(ev.button==0)
{
bool=true;
}
}
if(bool==true)
{ var div=window.document.getElementById(id);
div.onmouseup=up; //为"DIV"注册onmouseup事件
var x=parseInt(ev.clientX-div.offsetLeft);
var y=parseInt(ev.clientY-div.offsetTop);
window.document.documentElement.onmousemove=function(mEvent)
{
if(document.all)
{
div.style.left=(ev.clientX-x)+"px";
div.style.top=(ev.clientY-y)+"px";
}
else
{
div.style.left=(mEvent.clientX-x)+"px";
div.style.top=(mEvent.clientY-y)+"px";
}
}
}
} function up()
{
window.document.documentElement.onmousemove=null;
}
</script>
</head>
<body>
<div id="oDiv" onmousedown="down(event,'oDiv')" style="cursor:move;position:absolute;width:100px;height:60px;border:1px solid silver;left:100px;top:100px;z-index:9999;"> </div>
</body> </html>
function down(mevent,id)
{
var ev=mevent;
var bool=false;
if(document.all&&ev.button==1)
{
bool=true;
}
else
{
if(ev.button==0)
{
bool=true;
}
}
if(bool==true)
{ var div=window.document.getElementById(id);
// div.onmouseup=up; //为"DIV"注册onmouseup事件
var x=parseInt(ev.clientX-div.offsetLeft);
var y=parseInt(ev.clientY-div.offsetTop);
window.document.documentElement.onmousemove=function(mEvent)
{
if(document.all)
{
div.style.left=(ev.clientX-x)+"px";
div.style.top=(ev.clientY-y)+"px";
}
else
{
div.style.left=(mEvent.clientX-x)+"px";
div.style.top=(mEvent.clientY-y)+"px";
}
}
}
} function up()
{
window.document.documentElement.onmousemove=null;
}
</script>
</head>
<body>
<div id="oDiv" onmousedown="down(event,'oDiv')" onmouseup="up(event)" style="cursor:move;position:absolute;width:100px;height:60px;border:1px solid silver;left:100px;top:100px;z-index:9999;"> </div>
</body> </html>
我用的是ASP.NET.最后我把代码改了
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">//就是这段
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>无标题页</title>
<script type="text/javascript" language="javascript">
function down(mevent,id)
{
var ev=mevent;
var bool=false;
dd=id;
if(document.all&&ev.button==1)
{
bool=true;
}
else
{
if(ev.button==0)
{
bool=true;
}
}
if(bool==true)
{ var div=window.document.getElementById(id);
var x=parseInt(ev.clientX-div.offsetLeft);
var y=parseInt(ev.clientY-div.offsetTop);
window.document.documentElement.onmousemove=function(mEvent)
{
if(document.all)
{
div.style.left=(ev.clientX-x)+"px";
div.style.top=(ev.clientY-y)+"px";
}
else
{
div.style.left=(mEvent.clientX-x)+"px";
div.style.top=(mEvent.clientY-y)+"px";
}
}
}
}function up()
{
window.document.documentElement.onmousemove=null;
}
</script>
</head>
<body>
<div id="oDiv" onmousedown="down(event,'oDiv')" onmouseup="up()" style="cursor:move;position:absolute;width:100px;height:60px;border:1px solid silver;left:100px;top:100px;z-index:9999;"></div>
</body>
</html>最后发现在火狐浏览器里能正常运行!
在IE浏览器里只有把下面这段代码去掉才能正常运行了!!请问一下这是什么原因?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">