關(guān)于css(ps)
不懂為什么<script type="text/javascript">
//獲取尺寸,傳入CSS屬性組成的一個(gè)數(shù)組
//{width: "60px", height: "60px"}
var value = $('.first').css("width","height");
//因?yàn)楂@取的是一個(gè)對(duì)象,取到對(duì)應(yīng)的值
$('p:eq(2)').text( 'widht:' + value[0] + ?' height:' +value[1] );
$('p:eq(3)').text( 'widht:' + value.width() + ?' height:' +value.heigth );
$('p:eq(4)').text( 'widht:' + value.width + ?' height:' +value.heigth );
// $('p:eq(5)').text( 'widht:' + value.width() + ?' height:' +value.heigth() );
$("p:eq(6)").html(function(index,oldhtml){
? ?var a = [ "The clicked div has the following styles:" ];
? ? ? ? ? ?var styleProps = $( ".first").css([
? ? ? ? ? ?"width", "height"
? ? ? ? ? ?]);
? ? ? ? ? ?$.each( styleProps, function( prop, value ) {
? ? ? ? ? ?a.push( prop + ": " + value +"</br>");
? ? ? ? ? ?});
? ? ? ? ? ?return a;
});
? ?</script>
是這樣的運(yùn)行結(jié)果,value不是一個(gè)數(shù)組嗎?為什么可以value.width(),.width之類的而.height()就不行呢?ps:后面為自己添加的代碼
2017-09-08
這不是數(shù)組,數(shù)組格式是["a",“b","c"]。這里的{width: "60px", height: "60px"}是一個(gè)json格式的對(duì)象。后面value.width()就是?? 對(duì)象.屬性? 取值。js中一切都是對(duì)象