<html>
<body><script type="text/javascript">
var firstname;
firstname="George";
document.write(firstname);
document.write("<br />");
firstname="John";
document.write(firstname);
</script>
</body>
</html>
 
这段代码请过目~~ 其中第二个document.write输出的地方是("<br />"),有办法可以让变量和普通文本一同输出吗?不需要写两行输出,有没有方法类似于C++里面的 cout<<a<<"a is a varable"<<endl;

解决方案 »

  1.   


    <html>
    <body><script type="text/javascript">
    var firstname;
    firstname="George";
    document.write(firstname);
    document.write("\< br\ /> ");
    firstname="John";
    document.write(firstname);
    </script>
    </body>
    </html>
      

  2.   

    document.write(firstname + "<br />");
      

  3.   

    暗夜前辈,我想要的是通过一个document.write去同时输出变量和普通字符串,不知可否
      

  4.   


    <html>
    <body><script type="text/javascript">
    var name;
    name="George";document.write("test page:"+name+" ");//test page 是普通字符串可行呀!!
    name="John";
    document.write(name);
    </script>
    </body>
    </html>