富贵资源网 Design By www.hznty.com

非常简单,就用一个"+"将两个字符串"相加":

   var longString = "One piece " + "plus one more piece."; 


      要将多个字符串累积为一个字符串,还可以使用"+="操作符:

   var result = "";


   result += "My name is Anders"


   result += " and my age is 25"; 



   
      要在字符串中添加换行符,需要使用转义字符"":

   var confirmString = "You did not enter a response to the last " +
    "question.Submit form anyway";


   var confirmValue = confirm(confirmString);



      但这种方法只能用在像警告、确认对话框之类的情况下,如果将这段文本作为HTML内容呈现,就无效了,此时            用"<br>"代替它:

   var htmlString = "First line of string.<br>Second line of string.";


   document.write(htmlString);


 

      String对象还提供了方法concat(),它完成与"+"相同的功能:

   string.concat(value1, value2, ...)



      不过concat()方法显然不如"+"来得直观简洁。

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com