txt +=" "和txt = " "区别。待大神!

$("button").click(function(){
var txt=" ";
txt+="Width of div: " + $("#div1").width() + "
";
txt+="Height of div: " + $("#div1").height();
$("#div1").html(txt);
});

var txt=" "; 把字符串给txt
txt+="Width"; 在txt原本的字符串后加上字符串(Width)

txt="Width of div: " + $("#div1").width() + "

";
txt="Height of div: " + $("#div1").height();
我把它改成只能显示第二行;
为啥上面的代码能显示两行。

var txt ="asdf";
txt +="qwer";
此时txt="asdfqwer"
txt ="zxcv";
此时txt ="zxcv"
+=是在原有字符串基础上接上新的值。
=是赋值,原先的就被覆盖掉

+= 是连接复值,加号就是连接符,和上面的内容拼接起来

txt +=" "等价于 txt =txt +" "
txt = " "等价于 txt =" "

=是赋值语句,
+= 是运算符
建议还是先学习下基础的东西吧,要不这么多东西怎么问也是问不完的!