PhoneGap:JQueryMobile更新图像src不显示在设备上

问题描述:

我想在语法上修改标签的图像,而不是只在设备(Android,iOS)上工作。它在Chrome /桌面上运行良好。PhoneGap:JQueryMobile更新图像src不显示在设备上

我试图事业部跨度标签,但都有着相同的行为。

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

我已经搜索不到任何问题和尝试的选项,但没有为我工作。

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);"); 

注: - 我也试过背景图像:网址()背景:网址()但两者不上设备工作。

+0

你有没有找到解决办法? – 2015-10-22 13:50:15

问题是您正在使用background-image属性,如background速记属性。速记是background像这样

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

URL和重复属性,这样你的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应用这些样式( )方法,而不是改变样式属性。

+0

是的,我确实尝试过这种背景属性,但它不适用于设备。 – AAhad 2014-11-08 05:32:27

+0

这是有效的CSS,因此请以这种方式设置属性。它不会在设备上工作的唯一原因是因为图像不在这条路上。一个常见原因是大写字母的差异。 .PNG文件名与设备上的.png不同,但如果您在Windows计算机上开发,则不区分大小写 – kindasimple 2014-11-08 05:40:14