TimyChen 2016-01-10 11:19 采纳率: 100%
浏览 1521
已采纳

.innerHTML+="there are "中,=前面怎么会有+号?

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>example</title>
        <style type="text/css">
            pre{
                border: thin solid black;
            }
        </style>
    </head>
    <body>
         <pre id="results"></pre>
         <img id="caomei"src="img/4d0df8064383e78d74e07014e7ccd0ee.jpg" name="image" alt="caomei">
         <p id="tblock">
            There are lots of different kinds of fruit.There are over 500 varieties of <span id="banana">banana</span> alone.By the time we add the countless types of apples,oranges,and other well-known fruit,we are faced with thousands of choices.
         </p>
         <img id="apple" src="img/63fddd61e1afe42e38c6ce76910be815.jpg" name="image" alt="apple">
         <p>
            One of the most interesting aspects of fruit is the variety available in each country.I live near London,in an area which is known for its apples.
         </p>
         <img id="san" src="img/161026fa577b8f3aa88187bd67b546fd.jpg" alt="san" />
         <script>
            var resultsElement=document.getElementById("results");
            var elems=document.getElementById("tblock").getElementsByTagName("span");
            resultsElement.innerHTML+="there are "+elems.length+" span elements(getelement方法)\n";
            var elems2=document.getElementById("tblock").querySelectorAll("span");
            resultsElement.innerHTML+="there are "+elems2.length+" span elements(getelement+css方法)\n";
            var elems3=document.querySelectorAll("#tblock>span");
            resultsElement.innerHTML+="there are "+elems3.length+" span elements(css选择器方法)\n";
         </script>
    </body>
</html>
resultsElement.innerHTML+="there are "+elems3.length+" span elements(css选择器方法)\n";这句里面,=前面怎么会有+号?
  • 写回答

5条回答 默认 最新

  • threenewbee 2016-01-10 11:32
    关注

    +=表示保留之前的内容,并且把后面的附加上去。
    光是+,之间的文字就没有了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error