javascript - 在 JavaScript 中用 + 添加到 innerHTML 是什么意思?

标签 javascript operator-overloading operators innerhtml

我知道 innerHTML 在 JavaScript 中是如何工作的,就像下面的函数:

<html>
    <head>
        <title></title>
    </head>
    <body onLoad="changetext();">
        <div id="pp" onClick="changetext();">Click here</div>
        <script>
            function changetext(){
                document.getElementById("pp").innerHTML = "New Content!";  
            }
        </script>
    </body>
</html>

这导致 “新内容”。 但我也遇到过许多示例,其中 innerHTML++= 运算符一起使用,例如 W3Schools example .当我使用 + 添加到 innerHTML 时,这意味着什么?

最佳答案

elem.innerHTML +="abc" 表示它将追加 abcinnerHTML 元素

elem.innerHTML +="abc"

相当于

elem.innerHTML = elem.innerHTML + "abc"

关于javascript - 在 JavaScript 中用 + 添加到 innerHTML 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28603123/

相关文章:

python - XOR 运算符没有给出预期的结果?

javascript - JSLint 不期望我的波浪号

javascript - 悬停时跟踪 div?

javascript - 替换多个文档中的部分 HTML 字符串

c++ - 如何解决 "user-defined ' operator||( )' always evaluates both arguments"warning when -Weffc++ is opened?

c#-4.0 - C# 移位运算符重载

javascript - 在任何scrollTop分配上触发滚动事件

javascript - Google Chrome 中的 TypeScript 错误

c++ - 运算符重载的基本规则和惯用法是什么?

c++ - 重载 + 运算符的继承