gpt4 book ai didi

JavaScript 使用三元运算符更改高度

转载 作者:行者123 更新时间:2023-11-28 02:41:06 25 4
gpt4 key购买 nike

我试图在点击时更改宽度和高度,如果宽度已经是 100%,我想将其更改为 1400px,但不知何故以下不起作用:

document.getElementById('btnFullscreen').addEventListener('click', function() {
var wrapper = document.getElementById('wrapper');
var container = document.getElementById('container');
var imageView = document.getElementById('imageView');
var canvasBody = document.getElementById('canvas-body');


var items_arr = [canvasBody, videoPreview, wrapper, container, leftImageBox, imageView];

for (i = 0; i < items_arr.length; ++i) {
items_arr[i].style.width = items_arr[i].style.width != "100%;" ? "100%;" : "1400px;";
items_arr[i].style.height = items_arr[i].style.height != "100%;" ? "100%;" : "1400px;";
items_arr[i].style.minWidth = items_arr[i].style.minWidth != "100%;" ? "100%;" : "1400px;";
items_arr[i].style.minHeight = items_arr[i].style.minHeight != "100%;" ? "100%;" : "1400px;";
}
});

最佳答案

删除 ; 的 dom 值如 100%;。从这段代码 videoPreviewleftImageBox都是未定义的

document.getElementById('btnFullscreen').addEventListener('click', function() {
var wrapper = document.getElementById('wrapper');
var container = document.getElementById('container');
var imageView = document.getElementById('imageView');
var canvasBody = document.getElementById('canvas-body');
var items_arr = [canvasBody, videoPreview, wrapper, container, leftImageBox, imageView];

for (i = 0; i < items_arr.length; ++i) {
items_arr[i].style.width = items_arr[i].style.width != "100%;" ? "100%" : "1400px";
items_arr[i].style.height = items_arr[i].style.height != "100%;" ? "100%" : "1400px";
items_arr[i].style.minWidth = items_arr[i].style.minWidth != "100%;" ? "100%" : "1400px";
items_arr[i].style.minHeight = items_arr[i].style.minHeight != "100%" ? "100%" : "1400px";
}
});

关于JavaScript 使用三元运算符更改高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44456042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com