简体   繁体   English

如何使用JavaScript调整div宽度

[英]How to resize div width with javascript

I would like to resize the pagewrapper div with javascript. 我想用JavaScript调整pagewrapper div的大小。 I have chrome and would like to use it as userscript. 我有chrome,想将其用作用户脚本。 Here is the site link: http://clanbase.ggl.com . 这是网站链接: http : //clanbase.ggl.com I want to take the pagewrapper to 100% width. 我想将pagewrapper的宽度设为100%。 I have the following code: 我有以下代码:

// ==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);

One thing to note is that non-absolutely positioned divider elements automatically take up 100% of the width, so you might not need to do anything. 需要注意的一件事是,非绝对位置的分隔符元素会自动占据宽度的100%,因此您可能不需要执行任何操作。 Just try removing the width property from the pagewrapper element (in the CSS) and see if it works. 只需尝试从pagewrapper元素(在CSS中)中删除width属性,看看它是否有效。 You could also try overriding the width property: 您还可以尝试覆盖width属性:

#pagewrapper {
    width:100%;
}

If setting CSS isn't an option for whatever reason, this script should suffice: 如果出于任何原因不能设置CSS,则此脚本应足够:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM