【问题标题】:background image is not changing using jquery on IE 11在 IE 11 上使用 jquery 不会改变背景图像
【发布时间】:2019-06-05 23:47:05
【问题描述】:

亲爱的我试图在点击时使用 jquery 更改 div 背景图像,如下面的代码所示,它适用于除 IE 以外的所有浏览器.....请帮助

<div id="section1" class="section111">
        <div class="container">
            <div style="width: 100%; z-index: 999999999;" class="ServicesTitle">
                <p class="Main_TitaleServices">SERVICES & SOLUTIONS</p>
                <p class="slogan">Full Solutions for a Perfect Business   </p>
            </div>
            <div id="title-underline" style="margin-bottom: -30px;">
                <img src="../../App_Themes/ThemeEn/Images/title-underline.png">
            </div>
            <div class="firstrow">
                <div class="col-lg-3 divServices ">
                </div>
                </div>

        </div>
    </div>

这是脚本

<script>
$(function () {
$("#WebsiteDevelopment").click(function () {
    $("#section1").css("background-image", "url(/App_Themes/ThemeEn/Images/webdevelopment.jpg !important")
    /

});
$("#btnWebsiteDevelopment").click(function () {


    $("#section1").css("background-image", "url(/App_Themes/ThemeEn/Images/section1bg.png")

});
});
</script>

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

尝试设置background 而不是background-image

<script>
$(function () {
$("#WebsiteDevelopment").click(function () {
    $("#section1").css("background", "url(/App_Themes/ThemeEn/Images/webdevelopment.jpg !important")
    /

});
$("#btnWebsiteDevelopment").click(function () {


    $("#section1").css("background", "url(/App_Themes/ThemeEn/Images/section1bg.png")

});
});
</script>

或者使用纯javascript方法,

document.getElementById('section1').backgroundImage = "url('url(/App_Themes/ThemeEn/Images/webdevelopment.jpg !important')";

【讨论】:

  • 亲爱的 AKA,我尝试使用后台但仍然无法正常工作
  • 我已经更新了答案。使用带有 javascript 修复的第二个。
  • 很高兴为您提供帮助。
猜你喜欢
  • 2011-02-13
  • 2013-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-31
  • 2011-06-02
相关资源
最近更新 更多