小编Sta*_*ght的帖子

Javascript onload 不起作用(“Uncaught TypeError:无法将属性‘document.body’设置为 null ”)

这是我的代码:

\n\n

JavaScript:

\n\n
document.body.onload = function() {\n    function UP() {//\xe1\xba\xa8n hi\xe1\xbb\x87n n\xc3\xbat UP\n        if(window.pageYOffset > window.innerHeight)\n            document.getElementById(\'UP\').style.display = "block";\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

HTML 标签:

\n\n
<button id="UP" onclick="toTop(350);"></button>\n
Run Code Online (Sandbox Code Playgroud)\n\n

CSS 样式:

\n\n
#UP {display: none;}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的想法是当我向下滚动时,会出现向上按钮。但不知道为什么,它不会,甚至返回错误:“Uncaught TypeError: Cannot set property \'document.body\' of null”。当然,我确实改变了其他脚本,如下所示:

\n\n
function getReady() {\n    UP();\n}\nfunction UP() {//\xe1\xba\xa8n hi\xe1\xbb\x87n n\xc3\xbat UP\n    if(window.pageYOffset > window.innerHeight)\n        document.getElementById(\'UP\').style.display = "block";\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

HTML 标签:

\n\n
<body onload="getReady();">\n    <button id="UP" onclick="toTop(350);"></button>\n</body>\n
Run Code Online (Sandbox Code Playgroud)\n\n

更可怕的是。当我加载网站时,我没有看到 body 标记的 onload attr,并且浏览器没有为我返回任何错误。

\n\n

其他一些信息:\n我在两侧开发,Cr 和 FF,它们都说同样的问题。\n我正在研究 Wordpress …

javascript null onload

4
推荐指数
1
解决办法
2万
查看次数

无法使用 JavaScript 获取宽度属性

我的想法是当我点击按钮时,div#x 宽度会减少 1%。这是我的代码:

document.querySelector('#a').onclick = function() {
    var
        lost = document.querySelector('#x').style.width,
        lost = lost.slice(0, -1);
    lost = Number(lost);
    lost -= 1;
    document.querySelector('#x').style.width = lost + '%';
}
Run Code Online (Sandbox Code Playgroud)
nav#control {
    display: flex;
    flex-basis: 50px;
    align-items: center;
    justify-content: center;
    background: #FFF;
    padding: 5px;
    width: 100%
}

.knob {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    cursor: pointer
}

#b {
    position: relative;
    flex-grow: 1;
    background: #EFEFEF;
    margin: 0 10px;
    height: 30px
}
#x {
    position: absolute;
    background: #4C8EFA; …
Run Code Online (Sandbox Code Playgroud)

html javascript css dom-events

2
推荐指数
1
解决办法
8096
查看次数

这种语法(0 <x <10)在C++中做什么?

我认为这种语法0 < x < 10与这种语法相同0 < x && x < 10.但是,今天,我的计划证明我错了.通常,我不会问这类问题,做0 < x < 10什么?但编译器接受它,所以我希望它有某种功能.

这是我的代码的一部分:

if (0 <= grade < 59)
        letter = 'F';
    else if (60 <= grade < 69)
        letter = 'D';
    else if (70 <= grade < 79)
        letter = 'C';
    else if (80 <= grade < 89)
        letter = 'B';
    else if (90 <= grade <= 100)
        letter = 'A';
    else
        letter = '?';
Run Code Online (Sandbox Code Playgroud)

结果总是返回letter ='F',所以我认为编译器只考虑0 …

c++ operators

0
推荐指数
1
解决办法
121
查看次数

标签 统计

javascript ×2

c++ ×1

css ×1

dom-events ×1

html ×1

null ×1

onload ×1

operators ×1