学习w3school中的jq教程中,关于jQuery中的 width() 和 height() 方法中的一个地方不明白。
代码如下:
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
var txt="";
txt+="Width of div: " + $("#div1").width() + "</br>";
txt+="Height of div: " + $("#div1").height();
$("#div1").html(txt);
});
});
</script>
</head>
<body>
<div id="div1" style="height:100px;width:300px;padding:10px;margin:3px;border:1px solid blue;background-color:lightblue;"></div>
<br>
<button>显示 div 的尺寸</button>
<p>width() - 返回元素的宽度。</p>
<p>height() - 返回元素的高度。</p>
</body>
</html>见代码第9.10.11行,
为什么var txt=“”;
第10行和11行就成了 txt+=,跟javascript中的 “ x+=y等价于x=x+y” 也不一样呀?
这个 txt+= 在代码里是什么意思,作用是什么?
谢谢
Tang小溪
__innocence
随时随地看视频慕课网APP
相关分类