页面加载就去掉body style的属性 我想做到的一个效果是,通过JS去掉body属性里的style样式。我用通过$("body")[0].style.top='0px';设置但是不能实现。各位有没有更好的方法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我测试时,发现这个代码是没问题的,只是加载顺序问题。body里的style属性是一个插件注入进去的。 找到是那个组件设置的body样式,去掉就行了除非那个组件提供onload事件什么的,在这个事件中执行$("body")[0].style.top='0px';设置 我现在是想隐藏掉那块东西,没想到它在body的style那加上了高度。我弄了大半天,还是没去掉。 我加上这个也不行window.onload = function(){ document.body.style.top='0px';} 隐藏什么元素,设置样式为display:none;要不贴上代码看看 隐藏一个DIV,DIV的是被我隐藏了,但是它在<body style="top:40px">加了顶部间距。我想去掉这个。 不行只能setInterval检查了。。检查到有这个属性就去掉,如果google也有定时器检查body没有这个属性又加上就难搞了~ window.onload = function () { var timer = setInterval(function () { if (document.body.style.top) document.body.style.top = '0px'; clearInterval(timer);/// }, 100); } window.onload = function(){document.body.style.position='absolute';document.body.style.top='0px';} 调用的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> 不是gg翻译加的top:40px吧。。我这里看到是0px<body style="position: relative; min-height: 100%; top: 0px;"> 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> 这个应该是代码执行顺序的问题,用firebug跟踪下顺序。不过你隐藏它干吗,直接去掉不要不就是了? JS里的flot插件画柱状图时,怎么做对比 Microsoft JScript 运行时错误: 对象不支持此属性或方法 请教一个疑难问题 怎样保存选择的图片呢? 新手 求校验一个form中几百个文本框都不能为空的javascript写法 我得连接为什么没办法变成小手 各位Js大神们 问一个用 JavaScript 与 DIV 来做菜单的问题 关于:replace与RegEx 怎样动态增加页面内容 kindeditor-4.1.5 如何修改百度地图默认地址 checkbox选中状态在jquery加载后被移除
window.onload = function()
{
document.body.style.top='0px';
}
隐藏一个DIV,DIV的是被我隐藏了,但是它在<body style="top:40px">加了顶部间距。我想去掉这个。
var timer = setInterval(function () {
if (document.body.style.top) document.body.style.top = '0px';
clearInterval(timer);///
}, 100);
}
{
document.body.style.position='absolute';
document.body.style.top='0px';
}
<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>
<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>