程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> html-.innerHTML+=there are 中,=前面怎麼會有+號?

html-.innerHTML+=there are 中,=前面怎麼會有+號?

編輯:編程綜合問答
.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";這句裡面,=前面怎麼會有+號?

最佳回答:


+=表示保留之前的內容,並且把後面的附加上去。
光是+,之間的文字就沒有了。

TimyChen
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved