Javascript 数学运算符不适用于window.innerWidth
当我对window.innerWidth使用数学运算符时,它返回NaN 我刚刚尝试将数字1添加到窗口。innerWidth。Javascript 数学运算符不适用于window.innerWidth,javascript,jquery,Javascript,Jquery,当我对window.innerWidth使用数学运算符时,它返回NaN 我刚刚尝试将数字1添加到窗口。innerWidth。 我的代码怎么了 <body> <p>Click the button to display this window's height and width (NOT including toolbars and scrollbars).</p> <button onclick="myFunction()">Try
我的代码怎么了
<body>
<p>Click the button to display this window's height and width (NOT including toolbars and scrollbars).</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var w = window.innerWidth;
var h = window.innerHeight;
x = document.getElementById("demo");
x.innerHTML = "Width: " + w-1 + " Heigth: " + h;
}
</script>
</body>
单击按钮可显示此窗口的高度和宽度(不包括工具栏和滚动条)
试试看
函数myFunction(){
var w=窗内宽度;
var h=窗内高度;
x=document.getElementById(“演示”);
x、 innerHTML=“宽度:”+w-1+“高度:”+h;
}
将您的innerHTML代码更改为
x.innerHTML=“宽度:”+(w-1)+“高度:”+h代码>
修改javaScript代码如下
这是你的修改件
因为没有innerwidth
属性。@hindmost:你为什么这么想?javascript就是这样sensitive@user1386579将您的innerHTML设置为x.innerHTML=“宽度:”+(w-1)+“高度:”+h代码>有些人不知道如何处理他们的声誉
function myFunction() {
var w = window.innerWidth;
var h = window.innerHeight;
x = document.getElementById("demo");
x.innerHTML = "Width: " + (w-1) + " Heigth: " + h;
}