我想用用JQuery控制网页图片宽度如下:
<script type="text/javascript">
jQuery(function(){
$('img').each(function(){
var max = screen.width;
var w = $(this).width();
if (w > (max-100)) {
$(this).maxwidth = max-100;
}
});
});
</script>
可是这个并非都管用,
<img src="main.jpg" name="img1" width="2000" />
这个用width属性,所以管用,能获取到$(this).width()的值
<img src="main.jpg" name="img1" />
这个不管用,$(this).width()的值为0
请问应该怎么解决,怎样才能获取到所有width的值
<script type="text/javascript">
jQuery(function(){
$('img').each(function(){
var max = screen.width;
var w = $(this).width();
if (w > (max-100)) {
$(this).maxwidth = max-100;
}
});
});
</script>
可是这个并非都管用,
<img src="main.jpg" name="img1" width="2000" />
这个用width属性,所以管用,能获取到$(this).width()的值
<img src="main.jpg" name="img1" />
这个不管用,$(this).width()的值为0
请问应该怎么解决,怎样才能获取到所有width的值
<img src="main.jpg" name="img1" />
$(this).width()的值能获取到啊
<img ... onload="" />
没用过jQuery,我猜应该是
<script type="text/javascript">
jQuery(function(){
$('img').each(function(){
$(this).load(function(){
var max = screen.width;
var w = $(this).width();
if (w > (max-100)) {
$(this).maxwidth = max-100;
}
});
});
});
</script>
这个是js的相关问题,可以发到javascript区