代码之家  ›  专栏  ›  技术社区  ›  Stephan Muller

图像拒绝调整大小,即使通过开发人员工具?

  •  0
  • Stephan Muller  · 技术社区  · 14 年前

    this.lightboxImage.writeAttribute('width', newWidth) ,其中new width是计算出的新宽度),但没有结果。经过更多的测试,我设法检查了这些,以确保问题不在我的脚本中:

    • 新宽度计算正确
    • 写几个不同的属性都是成功的

    事实上,如果我跑:

    this.lightboxImage.writeAttribute('width', newWidth);
    alert(this.lightboxImage.readAttribute('width');
    

    我收到一个警告,显示600(我的新宽度,从1023px宽度调整)。即使在HTML中,脚本也会生成 <img src="pic.jpg" width="600" /> . 因此,我使用了dom检查器(Chrome和IE9中都有),并试图更改该值,但即使如此,图片仍然保持完整大小。

    这到底是怎么回事,我该怎么办?

    1 回复  |  直到 9 年前
        1
  •  0
  •   andrewmu    14 年前

    与其尝试更改width属性,不如尝试添加样式以使其更小,例如:

    this.lightboxImage.writeAttribute("style", "width: "+newWidth+"px");