【问题标题】:A jQuery code is not working in Google ChromejQuery 代码在 Google Chrome 中不起作用
【发布时间】:2016-11-16 19:58:52
【问题描述】:

下面是我的 HTML 结构。我想在第 4 个子 div 中添加 css 代码

  <div class="amazingcarousel-image">
    <div></div>
     <div></div>
     <div></div>
     <div></div>
  </div>

正常的 CSS 代码如下所示

.amazingcarousel-image div:nth-child(4) {
  display: none !important;
}

我想用jQuery添加上面的CSS,我已经添加了下面的代码

function tinda() {
    jQuery(".amazingcarousel-image div:nth-child(4)").css("cssText", "display: none !important;"); 
}

jQuery(document).ready(function() {
    tinda();
})

问题是这段代码在 Firefox 中运行良好,但在 Chrome 中却不行。请帮忙

【问题讨论】:

  • 它甚至不应该在 FF 中工作。 css("cssText", "display: none !important;") 应该是 css("display", "none")
  • 不要做.css("cssText", ...)。正确使用:.css("display", "none").
  • @MikeC .css() 不会接受 !important
  • @j08691 对了,忘了。

标签: javascript jquery css google-chrome firefox


【解决方案1】:
function tinda() {
    jQuery(".amazingcarousel-image div:nth-child(4)").addClass('hide'); 
}

.amazingcarousel-image div.hide {
    display: none !important;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    相关资源
    最近更新 更多