<br />是html的格式,被解析为换行\n换行字符。也就是说一个html标签,一个是字符。不是同一层面的东西。

解决方案 »

  1.   

    下面是.js的文件,3到6行的最后面"<br>\n"和"<br>"有什么区别?谢谢
    //define the functions
    function PrintCard(){
    line1="<b>name: </b>" + this.name + "<br>\n";
    line2="<b>Address: </b>" + this.address + "<br>\n";
    line3="<b>Work Phone:</b>" + this.workphone + "<br>\n";
    line4="<b>Home Phone: </b>" + this.homephone + "<hr>\n";
    document.write(line1,line2,line3,line4);
    }
    function Card(name,address,work,home){
    this.name=name;
    this.address=address;
    this.workphone=work;
    this.homephone=home;
    this.PrintCard=PrintCard;
    }
    //Create the objects
    sue=new Card("Sue Suthers","123 Elm Street","555-1234","555-9876");
    phred=new Card("Phred Madsen","233 Oak lane","555-2222","555-4444");
    henry=new Card("Henry Tillman","233 Walnut Circle","555-1299","555-1344");
    //And print them
    sue.PrintCard();
    phred.PrintCard();
    henry.PrintCard();
      

  2.   

    line1=" <b>name: </b>" + this.name + " <br>\n"; 
    line2=" <b>Address: </b>" + this.address + " <br>\n"; 
    line3=" <b>Work Phone: </b>" + this.workphone + " <br>\n"; 
    line4=" <b>Home Phone: </b>" + this.homephone + " <hr>\n"; 可以很负责的说,这里的\n没有任何意义。
    若改成如下:
    line1=" <b>name: </b>" + this.name + " <br>\n"; 
    line1+=" <b>Address: </b>" + this.address + " <br>\n"; 
    line1+=" <b>Work Phone: </b>" + this.workphone + " <br>\n"; 
    line1+=" <b>Home Phone: </b>" + this.homephone + " <hr>\n"; 这样写还有一点意思,就是在debugger的时候,看line1这个变量中的文本时,可以有换行的效果,这个换行的效果是由\n起作用的。而在页面上的换行是由<br>起作用的OK,放分吧~~~~~