jquery设置内联宽度属性问题
我使用的是jcarousel,我需要明确指定每个img的宽度。问题是,它必须实际看到 width="" 才能工作。有没有办法为图像添加内联宽度。我试过:
<script type="text/javascript">
$(document).ready(function () {
$('.tab-item-photo img').each(function () {
$(this).css("width", "100px");
});
});
它更改图像大小,但不会将宽度添加到内联样式,因此 jcarousel 的功能不起作用。
对此有什么想法吗?
谢谢, H.
I am using a jcarousel, and I need to explicitly specify the width of each img. The problem is, that it has to actually see the width="" to work. Is there a way to add an inline width to image. I tried:
<script type="text/javascript">
$(document).ready(function () {
$('.tab-item-photo img').each(function () {
$(this).css("width", "100px");
});
});
It changes the image size but it doesn't add the width to inline style so the functionality of jcarousel doesn't work.
Any ideas on this?
Thanks,
H.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是设置 css 属性,但听起来你在谈论宽度属性。尝试
$(this).attr('width', '100px');
编辑:实际上有一种更简单的方法来实现相同的功能,而且不会那么冗长。
上面的语句相当于
如果将
css
更改为attr
不起作用,您还可以尝试将其添加到 style 属性。如果您知道样式属性已经为空,则可以执行此操作。否则,您必须从现有样式属性中解析宽度并将其添加回来。理想情况下,您只需使用
.css() 但这显然不适合你的 jcarousel 代码。
That's setting the css property, but it sounds like you're talking about the width attribute. Try
$(this).attr('width', '100px');
EDIT: There's actually an easier way to implement the same thing that would be a bit less verbose.
Your statement above would be the equivalent of
If changing
css
toattr
doesn't work, you could also try adding it to the style attribute. If you know the style attribute is already empty, you could doOtherwise, you would have to parse width out of the existing style attribute and add it back in. Ideally, you would just do this with
.css()
but that apparently doesn't play well with your jcarousel code.