zoukankan      html  css  js  c++  java
  • <!DOCTYPE html PUBLIC 导致js代码不可用

    在有了这个

    <!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">标记的时候,说明这里引用的JS以及CSS都要符合编码规范,有些JS编写不符合规范,可能会导致

    无法正常运行。

    解决这个问题的方法:这是因为加入DOCTYPE申明后,js里是不能使用document.body的,一定要改成document.documentElement,还有就是加"px"。

    修改前:
    ...
    width = document.body.clientWidth;
    height = document.body.clientHeight;
    Hoffset = img1.offsetHeight;
    Woffset = img1.offsetWidth;
    img1.style.left = xPos + document.body.scrollLeft;
    img1.style.top = yPos + document.body.scrollTop;
    ...
    修改后:
    ...
    width = document.documentElement.clientWidth;
    height = document.documentElement.clientHeight;
    Hoffset = qingrenjie_pd.offsetHeight;
    Woffset = qingrenjie_pd.offsetWidth;
    img1.style.left = xPos + document.documentElement.scrollLeft + "px";
    img1..style.top = yPos + document.documentElement.scrollTop + "px";
  • 相关阅读:
    python连接字符串的几种方法--转子(香草拿铁的园子)
    winform属性
    C# Timer
    SQL基础
    SQL 基础
    File类 ReadAllBytes() ReadAllLines() ReadAllText()
    学习C#20天有感
    装箱和拆箱
    机器学习基础:朴素贝叶斯小结
    分类问题样本不均衡问题
  • 原文地址:https://www.cnblogs.com/eyunhua/p/3756411.html
Copyright © 2011-2022 走看看