我有一個問題,我想只使用Javascript和JQuery設置div內圖像的高度和寬度。使用javascript和jquery設置div內部圖像的高度和寬度
這裏是我的代碼:
<div class="myGallery">
<img class="replaced" src="myimage.jpg" style="display: inline;">
</div>
.myGallery {
display: table-cell;
height: 220px;
text-align: center !important;
vertical-align: middle !important;
width: 110px;
}
.myGallery img {
text-align: center;
vertical-align: middle;
width: auto !important;
}
function ChangeHW(hdnValue)
{
if (hdnValue==1)
{
//i want to remove height and width attribute of image
//this is working..
$('div.myGallery > img').removeAttr('width');
$('div.myGallery > img').removeAttr('height');
}
else
{
//i want to set height and width attribute of image
//this is not working..i cant set width-height using this line od code
$('div.myGallery > img').css('width', '110px');
$('div.myGallery > img').css('height', '220px');
}
}
任何想法?
.attr()not working .. – ravidev