【问题标题】:Jquery/Javascript and Css condition doesn't work on firefox and IE. It works on ChromeJquery/Javascript 和 Css 条件不适用于 firefox 和 IE。它适用于 Chrome
【发布时间】:2012-11-22 21:39:49
【问题描述】:
$('.myclassname').mouseover(function(){

  if($(this).children('span').css('font-weight')=='normal')

  {..do something... }

}

为什么“做某事”在 Chrome 上有效,但在 Firefox 16 和 Internet Explorer 9 上无效? 如果我删除 if 条件,它可以工作,但我需要它,所以我不能删除。 这是css

div.myclassname span {...; font-weight:normal ; ...}

【问题讨论】:

  • 您能发布一个您正在使用的 HTML 标记的示例吗?
  • 你真的在{}之前有一个空行吗?

标签: javascript jquery css firefox if-statement


【解决方案1】:

试试,

if($(this).children('span').css('font-weight')=='400')

或

if($(this).children('span').css('font-weight')==400)

在这里查看 http://jsfiddle.net/muthkum/qpEK2/2/ font-weight 在 JS 中返回 400。

【讨论】:

  • 它工作!在 Firefox 和 IE 上测试。
  • 对不起。我必须更精确。 400 仅适用于 IE 和 FF。不适用于 Chrome。为了使它起作用,我添加了一个 OR 和我的原始条件“正常”。如果您有其他解决方案,请随时编写。谢谢
  • @CalCon 我会通过添加OR 条件来做同样的事情。
【解决方案2】:

试试这个:

if($(this).children('span').eq(0).css('font-weight')=='normal')

【讨论】:

    【解决方案3】:

    你能在 jsfiddle 中设置它吗?是否:

    $('.myclassname').mouseover(function(){
        $('span',$(this)).each(function(){
          if($(this).css('font-weight')=='normal'){
           //do something
          }
        });
    });
    

    工作?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      • 2013-04-22
      • 2011-02-20
      • 2014-07-23
      • 1970-01-01
      • 2012-05-27
      相关资源
      最近更新 更多