我试图在Chrome中使用HTML编辑网页的宽度和高度,使用按钮
I'm trying to edit the width and height of a webpage in Chrome with HTML, using buttons
考虑我目前的代码:
<!DOCTYPE html>
<html>
<body>
<input id="but" name="but" type=Button onclick="changeBCol();" value="Shuffle Background Colour"></input>
<br></br>
<button style="background-color:transparent;width:255;height:255" onclick = "w = w+1">Window width up</button>
<br></br>
<button style="background-color:transparent;width:255;height:255">Window width down</button>
<br></br>
<button style="background-color:transparent;width:255;height:255">Window height up</button>
<br></br>
<button style="background-color:transparent;width:255;height:255">Window height down</button>
<script>
var w = window.innerWidth
</script>
</html>
</body>
目前还不能使用,如有任何建议,我将不胜感激。
因为您只是更改变量w
的值(它不包含引用但包含值),而不是窗口的宽度或高度。另外你只能改变宽度&我不认为这是一个好主意,试图改变窗口的宽度&但是如果你想这样做,可以考虑使用window.resizeTo()。
+:
- 将
<br></br>
改为<br>
,<input></input>
改为<input>
。它们是void元素,没有结束标签。 - 内层为内层,外层为外层:应该是
<html>...<body>...</body></html>
。 - 你应该指定
<button>
s的类型,因为默认是type="submit"
。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="author" content="K.">
<title>Demo</title>
</head>
<body>
<div id="demoButtons">
<button id="incWidth" type="button">Increase its width</button>
<button id="decWidth" type="button">Decrease its width</button>
<button id="incHeight" type="button">Increase its height</button>
<button id="decHeight" type="button">Decrease its height</button>
</div>
<script>
let width = 100, height = 100;
childWindow = window.open("", "", "width=100, height=100");
childWindow.focus();
document.getElementById("demoButtons").addEventListener("click", event => {
console.log(event.target.id);
/**/ if(event.target.id === "incWidth") width += 100;
else if(event.target.id === "decWidth" && width >= 100) width -= 100;
else if(event.target.id === "incHeight") height += 100;
else if(event.target.id === "decHeight" && height >= 100) height -= 100;
console.log(width, height);
childWindow.resizeTo(width, height);
childWindow.document.textContent = `The width: ${width}, the height: ${height}.`;
childWindow.focus();
});
</script>
</body>
</html>
标题>
相关文章:
- 在按钮改变高度后使标题保持不变
- 谷歌登录按钮的宽度和高度问题
- 当改变比例按钮具有不同的高度时
- 通过命令按钮单击更改丰富面可扩展数据表高度
- 幻灯片JS高度和按钮定位问题
- 使按钮的宽度与高度相同
- 按下按钮使$(“身体”).css(“高度”:“100%”)
- 表单“提交”按钮文本(和宽度/高度/值)在按键时消失或更改BTN值
- 具有上一个/下一个按钮的固定宽度和高度的文本容器
- 如何使用谷歌图表onclick引导选项卡按钮固定宽度和高度
- jQuery-在Iframe内按钮的onclick事件中更改Iframe高度
- jQuery/CSS-单击IFRAME内容内的按钮时更改IFRAME高度
- 如何在单击Iframe内部的按钮时更改Iframe高度'的内容
- 设置高度'单击按钮时元素的s
- 当innerhtml被替换时,Jquery Mobile按钮失去高度
- Bootstrap -每个环境中按钮和文本字段的动态高度大小
- 设置Dojo's按钮高度%
- 我试图在Chrome中使用HTML编辑网页的宽度和高度,使用按钮
- 阅读更多按钮,逐渐删除最大高度
- 如何在HTML中更改按钮的高度?