【问题标题】:PhoneGap: JQueryMobile updating image src not showing on devicePhoneGap:JQueryMobile 更新图像 src 未显示在设备上
【发布时间】:2014-11-08 03:21:25
【问题描述】:

我想在语法上修改标签的图像,它不仅适用于设备(​​Android、iOS)。它在 Chrome/桌面上运行良好。

我尝试了 DivSpanImg 标签,但都具有相同的行为。

请指导我如何更改背景图像。

我已经搜索了 no# 个问题并尝试了选项,但对我来说没有任何效果。

HTML

<div class="healthCare_heading">
    <span class="healthCare_heading span" onclick="Utilities.switchResultsULMaps('PageUL', 'MapsDiv')"></span>
</div>

CSS

.healthCare_heading {
    float: left;
    width: 100%;
    box-shadow: inset 0 0 0 1000px rgba(13, 13, 13, 0.8);
}
.healthCare_heading span {
    float: right;
    margin-right: 0;
    background-image: url(../images/phone/1x/healthIcon.png) ;
    background-size: 25px 25px;
    width: 30px;
    height: 30px;
    background-position: center;
    background-color: rgba(16,138,177,0.6);
}

我正在使用下面的JS代码来改变背景。

$(".healthCare_heading span").attr("style", "background-image:url(../images/phone/1x/healthCareBar_icon.png) no-repeat;margin-left: 0;background-size: 25px 25px;width: 30px;height: 30px;background-position: center;background-color: rgba(16,138,177,0.6);");

注意:- 我也试过 background-image:url()background:url() 但两者都不能在设备上工作。

【问题讨论】:

  • 你找到解决办法了吗?

标签: javascript jquery css cordova


【解决方案1】:

问题是您正在使用background-image 属性,例如background 速记属性。简写是background,带有这样的 url 和重复属性

background: url('../images/phone/1x/healthCareBar_icon.png') no-repeat;

所以你的 jquery 会是

$(".healthCare_heading span").attr("style", "background: url('../images/phone/1x/healthCareBar_icon.png') no-repeat;margin-left: 0;background-size: 25px 25px;width: 30px;height: 30px;background-position: center;background-color: rgba(16,138,177,0.6);");

您可能需要考虑使用 css 类选择器和 jQuery .addClass() 方法应用这些样式,而不是更改样式属性。

【讨论】:

  • 是的,正确,我确实尝试过这个背景属性,但它在设备上不起作用。
  • 这是有效的 css,所以保持这种方式设置属性。它无法在设备上运行的唯一原因是图像不在该路径上。一个常见的原因是大小写不同。 .PNG 文件名与设备上的 .png 不同,但如果您是在 Windows 机器上开发,则它不区分大小写
猜你喜欢
  • 2018-05-27
  • 2014-08-22
  • 2014-07-24
  • 1970-01-01
  • 1970-01-01
  • 2019-10-20
  • 2020-10-05
  • 2021-09-28
  • 2015-06-21
相关资源
最近更新 更多