简体   繁体   English

jQuery .attr不指定宽度或高度

[英]jQuery .attr doesn't attribute width or height

The following code attributes the src to .ajax-loader which is an img but not the height or width. 以下代码将src归因于.ajax-loader ,这是一个img但不是高度或宽度。 Am I doing something wrong? 难道我做错了什么?

  $(".ajax-loader").attr({
    src: "http://test.com/loading.gif",
    height: 16,
    width: 16
  });

Edit: This is being loaded by Contact Form 7 which is a WordPress plugin. 编辑:这是由联系表单7(这是一个WordPress插件)加载的。 I don't understand because the src is changing fine. 我不明白,因为src的变化很好。 However, one thing I noticed was that the height and width attributes aren't present. 但是,我注意到的一件事是高度和宽度属性不存在。 I am trying to add them in. Is this why they aren't showing up? 我正在尝试添加它们。这就是为什么它们不出现的原因?

Link to website 链接到网站

You could use .css() : 您可以使用.css()

$(".ajax-loader").attr("
    "src", "http://keebs.com/wp-content/themes/keebs/images/ajax-loader.gif")
   .css({
    height: "16px",
    width: "16px"
  });

您需要更新CSS的height和width属性: $(".ajax-loader").css({height:"16px", width:"16px"});

使用.height()和.width()设置宽度和高度。

$(".ajax-loader").width(16).height(16);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM