比如这样一段代码:<script type="text/javascript">
//<![CDATA[
function show(){
alert("hello,world");
}
document.body.onmousedown=show;//]]</script>如果在html页面加上了DTD就运行不了,如果去掉了,就可以有效弹出,这个问题只是发生在body标签上,就是body标签上加上的事件句柄,如果html上有DTD,就不能运行,去掉了DTD,却又可以了,求解.其他标签没有问题,就是body标签出问题了

解决方案 »

  1.   

    DTD 下 body内容的高度就是body的高度。比如 ,这个例子,点击div之外 是不能调show函数的
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="gb2312" />
    <title></title> <style>
    div{
    height:200px; border:1px solid red;
    }
    </style>
    </head>
    <body>
    <div>div</div>
    <script type="text/javascript">
    //<![CDATA[
    function show(){
    alert("hello,world");
    }
    document.body.onmousedown=show;
    //]]</script>
    </body>
    </html>
    如果想要 点击div外的内容也调用show
    那么这样, 定义body的height
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="gb2312" />
    <title></title> <style>
    html, body {
    height:100%;
    }
    div{
    height:200px; border:1px solid red;
    }
    </style>
    </head>
    <body>
    <div>div</div>
    <script type="text/javascript">
    //<![CDATA[
    function show(){
    alert("hello,world");
    }
    document.body.onmousedown=show;
    //]]</script>
    </body>
    </html>