火狐中jQuery设置某个class的img标签的width指的问题

index.html
    <img class="ability-img" ... />
    <img class="ability-img" ... />
    <img class="ability-img" ... />
    <img class="ability-img" ... />

index.js
    $(".ability-img").css({
        width : parseInt($("#championHead").width()) * 64 / 120,
        height : "auto"
    });
    alert(parseInt($("#championHead").width()) * 64 / 120);
    alert($(".ability-img").width());

第一个弹窗弹出52,计算结果正确,但是问题来了
第二个弹窗弹出64,这是为什么?(图片原大小为64px)
只有火狐会出现这种效果,用edge和谷歌两个弹窗都为52,一切正常。

求指教!

围观,表示不解。等大神解答

你的ability-img样式有什么,贴出来看下

$("#championHead").width()
$(".ability-img").width()
alert一下这两个是什么

火狐和其他浏览器,第一css不兼容,第二js抓取的对象也不一样,语法也不一样,你用同样的语法是行不通的

指定一下dtd看看效果

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

不知道是应用什么场景 本地测试火狐下是没问题的













<br> $(&quot;.ability-img&quot;).css({<br> width: parseInt($(&quot;#championHead&quot;).width()) * 64 / 120,<br> height: &quot;auto&quot;<br> });<br> alert(parseInt($(&quot;#championHead&quot;).width()) * 64 / 120);<br> alert($(&quot;.ability-img&quot;).width());<br>

 <html>
<head>
    <title></title>
    <meta charset="utf-8">
    <script src="http://libs.useso.com/js/jquery/1.10.0/jquery.min.js"></script>
</head>
<body>
    <div id="championHead">
        <img class="ability-img" src="Image/P/2.jpg" />
        <img class="ability-img" src="Image/P/3.jpg" />
        <img class="ability-img" src="Image/P/4.jpg" />
        <img class="ability-img" src="Image/P/5.jpg" />
    </div>
    <script>
        $(".ability-img").css({
            width: parseInt($("#championHead").width()) * 64 / 120,
            height: "auto"
        });
        alert(parseInt($("#championHead").width()) * 64 / 120);
        alert($(".ability-img").width());
    </script>
</body>
</html>