【问题标题】:Replace style of an html element jquery替换 html 元素 jquery 的样式
【发布时间】:2015-12-03 06:58:31
【问题描述】:

在下面的html元素中,

<canvas style="padding: 0px; margin: 0px; border: 0px none; background: transparent none repeat scroll 0% 0%; position: absolute; top: 0px; left: 0px; width: 1017.5px; height: 226.5px;" ></canvas>

我只需要将样式属性中的宽度和高度替换为其他值。如何使用 jQuery 实现这一点?

谢谢...

【问题讨论】:

  • $('canvas').width(newWidthValue).height(newHeightValue)

标签: jquery replace styles


【解决方案1】:
<canvas style="padding: 0px; margin: 0px; border: 0px none; background: transparent none repeat scroll 0% 0%; position: absolute; top: 0px; left: 0px; width: 1017.5px; height: 226.5px;" ></canvas>

更改widthheight

$('canvas').width(w).height(h);

这些wh 是新值,应该在px 中。

【讨论】:

    【解决方案2】:

    您也可以使用css() 参数更改此设置

    newWidth = 400;
    newHeight= 400;
    $("canvas").css({width:newWidth, height:newHeight})
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <canvas style="padding: 0px; margin: 0px; border: 0px none; background: #000 none repeat scroll 0% 0%; position: absolute; top: 0px; left: 0px; width: 1017.5px; height: 226.5px;" ></canvas>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 1970-01-01
      • 2016-08-24
      相关资源
      最近更新 更多