| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 917 人关注过本帖
标题:加了DOCTYPE导致js在火狐浏览器中失效
只看楼主 加入收藏
lsjayls
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2008-12-23
结帖率:100%
收藏
 问题点数:0 回复次数:1 
加了DOCTYPE导致js在火狐浏览器中失效
程序代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.拖动效果函数演示</title>
<style>
body
{
    font-size:12px;
    color:#333333;
    border : 0px solid blue;
}
div
{
    position : absolute;
    background-color : #c3d9ff;
    margin : 0px;
    padding : 5px;
    border : 0px;
    width : 100px;
    height:100px;
}
#nnn
{
    width:10px;
    height:10px;
    border:1px; border-color:Green; border-style:solid
}
</style>
</head>
<body>
<script>
function drag(o,s)
{
    if (typeof o == "string") o = document.getElementById(o);
    o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
    o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
    o.orig_index = o.style.zIndex;
       
    o.onmousedown = function(a)
    {
        this.style.cursor = "move";
        this.style.zIndex = 10000;
        var d=document;
        if(!a)a=window.event;
        var x = a.clientX+d.body.scrollLeft-o.offsetLeft;
        var y = a.clientY+d.body.scrollTop-o.offsetTop;
        //author: www.
        d.ondragstart = "return false;"
        d.onselectstart = "return false;"
        d.onselect = "document.selection.empty();"
               
        if(o.setCapture)
            o.setCapture();
        else if(window.captureEvents)
            window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);

        d.onmousemove = function(a)
        {
            if(!a)a=window.event;
            o.style.left = a.clientX+document.body.scrollLeft-x;
            o.style.top = a.clientY+document.body.scrollTop-y;
            o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
            o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
        }

        d.onmouseup = function()
        {
            if(o.releaseCapture)
                o.releaseCapture();
            else if(window.captureEvents)
                window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
            d.onmousemove = null;
            d.onmouseup = null;
            d.ondragstart = null;
            d.onselectstart = null;
            d.onselect = null;
            o.style.cursor = "normal";
            o.style.zIndex = o.orig_index;
        }
    }
   
    if (s)
    {
        var orig_scroll = window.onscroll?window.onscroll:function (){};
        window.onscroll = function ()
        {
            orig_scroll();
            o.style.left = o.orig_x + document.body.scrollLeft;
            o.style.top = o.orig_y + document.body.scrollTop;
        }
    }
}
</script>

<div id="div1" style="left:10px;top:10px;">div1:我可以被拖动<div id="nnn"></div><div id="nnn"></div><div id="nnn"></div></div>
<div id="div2" style="left:120px;top:10px;background-color : #f3d9ff">div2:来拖我呀</div>
<div id="div3" style="left:230px;top:10px;background-color : #c3ffff">div3:我随便你拖</div>
<div id="div4" style="left:10px;top:120px;background-color : #c3d944">div4:我可以随窗口滑动,把我拖到最下面,然后滚动网页看看</div>
<div id="div5" style="left:120px;top:120px;background-color : #f3d944"></div>
<div id="div6" style="left:230px;top:120px;background-color : #e3f944;width:200px;">参数说明:<br/>
drag(obj [,scroll]);<br/>
obj:对象的id或对象本身;<br/>
scroll(可选):对象是否随窗口拖动而滑动,默认为否<br/>
鼠标右键查看源代码
</div>

<script>
drag("div1");
drag("div2");
drag("div3");
drag("div4",1);
drag("div5",1);
drag("div6",1);
</script>

</body>
</html>
这段代码,如果删了开头的<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.的话,在FF里就生效,否则不可移动

但<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.很重要
不能删,求助啊求助
搜索更多相关主题的帖子: 火狐浏览器 DOCTYPE 失效 
2010-06-14 12:03
qingshuiliu
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:17
帖 子:323
专家分:1538
注 册:2009-12-28
收藏
得分:0 
<script type="text/javascript">
 var OsObject = "";
   if(navigator.userAgent.indexOf("MSIE")>0) {     
   }
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
   }
</script>
2010-06-17 09:38
快速回复:加了DOCTYPE导致js在火狐浏览器中失效
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.103511 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved