用JS写了一个乘法口诀表可是换行语句遇到了困难

 <script type="text/javascript">



function chengfakoujue(){

    var str="";

    for(var i=1;i<=9;i++){

        for(var j=1;j<=i;j++)

        document.write(j+"*"+i+"="+(i*j)+" ");

        }

        document.write("在这一行求一条可以用的换行语句");

    }

    document.getElementById("chengfakoujue").innerHTML=chengfakoujue();

</script>

http://www.chinadmd.com/file/vrarstp6wiwtwpo6xsruptow_1.html

http://www.chinadmd.com/file/vrarstp6wiwtwpo6xsruptow_1.html

你们发的链接我咋都上不去

打出来html的换行标签就行了

< br />


换成这个就行了

 <div id="chengfakoujue"></div>
    <script type="text/javascript">



        function chengfakoujue() {

            var str = "";

            for (var i = 1; i <= 9; i++) {

                for (var j = 1; j <= i; j++)

                    str+=(j + "*" + i + "=" + (i * j) + " ");

                str += ("<br>");//////////////位置要放对
            }

            return str;

        }

        document.getElementById("chengfakoujue").innerHTML = chengfakoujue();

    </script>

<br> function chengfakoujue(){</p> <pre><code> var str=&quot;&quot;; for(var i=1;i&lt;=9;i++){ for(var j=1;j&lt;=i;j++){ document.write(j+&quot;*&quot;+i+&quot;=&quot;+(i*j)+&quot; &quot;); } document.write(&quot;&lt;/br&gt;&quot;); } } document.getElementById(&quot;chengfakoujue&quot;).innerHTML=chengfakoujue(); &lt;/script&gt; </code></pre>

你的循环写错了 for(var j=1;j<=i;j++)

    document.write(j+"*"+i+"="+(i*j)+" ");

改成 for(var j=1;j<=i;j++){

    document.write(j+"*"+i+"="+(i*j)+" ")}
             document.write("</br>");;这样试试

<br> function chengfakoujue(){</p> <pre><code> var str=&quot;&quot;; for(var i=1;i&lt;=9;i++){ ** for(var j=1;j&lt;=i;j++){ document.write(j+&quot;*&quot;+i+&quot;=&quot;+(i*j)+&quot; &quot;); }** document.write(&quot;&lt;/br&gt;&quot;); } } document.getElementById(&quot;chengfakoujue&quot;).innerHTML=chengfakoujue(); &lt;/script&gt; </code></pre>