4

我想用 javascript 调整 pagewrapper div 的大小。我有 chrome 并想将其用作用户脚本。这是网站链接:http ://clanbase.ggl.com 。我想将页面包装器设为 100% 宽度。我有以下代码:

// ==UserScript==
// @match http://clanbase.ggl.com/*
// ==/UserScript==

function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}

function pagewrapper() {
document.getElementById('pagewrapper').style.Width = "100%";
}

addJQuery(pagewrapper);
4

1 回答 1

5

需要注意的一点是,非绝对定位的分隔元素会自动占据 100% 的宽度,因此您可能不需要做任何事情。只需尝试从pagewrapper元素中删除 width 属性(在 CSS 中),看看它是否有效。您也可以尝试覆盖 width 属性:

#pagewrapper {
    width:100%;
}

如果由于某种原因无法设置 CSS,则此脚本就足够了:

function pagewrapper() {
    document.getElementById('pagewrapper').style.width = "100%";
}
于 2012-10-07T13:11:04.993 回答