我想做到的一个效果是,通过JS去掉body属性里的style样式。
我用通过$("body")[0].style.top='0px';设置但是不能实现。
各位有没有更好的方法。

解决方案 »

  1.   

    我测试时,发现这个代码是没问题的,只是加载顺序问题。body里的style属性是一个插件注入进去的。
      

  2.   

    找到是那个组件设置的body样式,去掉就行了除非那个组件提供onload事件什么的,在这个事件中执行$("body")[0].style.top='0px';设置
      

  3.   

    我现在是想隐藏掉那块东西,没想到它在body的style那加上了高度。我弄了大半天,还是没去掉。
      

  4.   

    我加上这个也不行
    window.onload = function()
    {
    document.body.style.top='0px';
    }
      

  5.   

    隐藏什么元素,设置样式为display:none;要不贴上代码看看
      

  6.   


    隐藏一个DIV,DIV的是被我隐藏了,但是它在<body style="top:40px">加了顶部间距。我想去掉这个。
      

  7.   

    不行只能setInterval检查了。。检查到有这个属性就去掉,如果google也有定时器检查body没有这个属性又加上就难搞了~    window.onload = function () {
            var timer = setInterval(function () {
                if (document.body.style.top) document.body.style.top = '0px';
                clearInterval(timer);///
            }, 100);
        }
      

  8.   

    window.onload = function()
    {
    document.body.style.position='absolute';
    document.body.style.top='0px';
    }
      

  9.   

    调用的JS
    <script type="text/javascript">
    function googleTranslateElementInit() {
      new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'de,es,fr,it,pt,ru'}, 'google_translate_element');
    }
    </script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script><script>
       window.onload = function () {
            var timer = setInterval(function () {
                if (document.body.style.top) document.body.style.top = '0px';
                clearInterval(timer);///
            }, 100);
        }

    </script>
      

  10.   

    不是gg翻译加的top:40px吧。。我这里看到是0px<body style="position: relative; min-height: 100%; top: 0px;">
      

  11.   

    firefox的firebug插件,IE8的开发人员工具,chrome也没有你说的top:40px,都是top:0px
    <body>
    <script type="text/javascript">
    function googleTranslateElementInit() {
      new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'de,es,fr,it,pt,ru'}, 'google_translate_element');
    }
    </script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
    </body>
      

  12.   

    这个应该是代码执行顺序的问题,用firebug跟踪下顺序。不过你隐藏它干吗,直接去掉不要不就是了?