当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JavaScript中“+=”的应用

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 JavaScript中“+=”的应用


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-10   浏览: 399 ::
收藏到网摘: n/a

加法赋值运算符 (+=)。将变量值与表达式值相加,并将和赋给该变量。
在写JavaScrpt的时候经常会用到,说实话我以前不是很理解。看了很多的代码感觉就是因为一个变量太长了用它来分几行来写罢了。但它和解决了我其他的问题。
在一些时候我们需要使用一系列的HTML代码来作为变量,而HTML里面有时时会包含一些引号。比如
复制代码 代码如下:

var Nameform='<div id="PointName"><input id="PointNameText" type="text" size=18 value="请在此输入地标名" class="inputField" onFocus="this.value=null" onBlur="this.value='请在此输入地标名'"/></div>';

这时候你会发现引号的问题始终困扰着你。这时候用'+='就解决问题了。
复制代码 代码如下:

var Nameform='<div id="PointName"><input id="PointNameText" type="text" size=18 value="请在此输入地标名" class="inputField" onFocus="this.value=null" onBlur="this.value=';
Nameform+="'";
Nameform+='请在此输入地标名';
Nameform+="'";
Nameform+='"/></div>';