【问题标题】:Cufon don't exclude the elements with the selector :notCufon 不排除带有选择器的元素:不
【发布时间】:2012-07-30 10:15:14
【问题描述】:

我在网上搜索并在 stackoverflow 上找到了 exclude an element 的 Cufon 转换的解决方案,因为我的字体 'BlueHighwayDType' 不包含 '' 符号,所以我必须排除这个元素才能在 ie7/8 上看到它。 http://www.matteowebdesigner.com/test/yesimove/

<!--head-->
<!--[if lt IE 9]>
<script type="text/javascript" src="js/cufon-yui.min.js"></script>
<script type="text/javascript" src="js/Blue_Highway_D_Type_400.font.js"></script>
<script type="text/javascript" src="js/mind-ie.js"></script>
<![endif]-->

我要替换的元素是 p,我要排除的元素是 span.small

<!--body-->
<article>
    <p>L'unico <strong>Personal Trainer</strong> <br/>
    che ti segue ovunque</p>
    <p>e ti permette di <strong>condividere</strong> 
    i tuoi progressi con i tuoi amici.</p>
    <p>A soli <strong>9.<span class="small">99 &euro;</span></strong> al mese !</p>
</article>

所以我尝试了我在网上找到的示例,并使用了选择器“:not”,但它不起作用。看这个:

/*mind-ie.js*/
$(document).ready(function() { // Start Functions
    Cufon.replace('#main #slogan section article p:not(.small)');
});

我不明白,因为它不起作用,我认为选择器是正确的。

【问题讨论】:

    标签: jquery jquery-selectors fonts font-face cufon


    【解决方案1】:

    即使在这种情况下排除所有 span 元素。

    Cufon.replace('#main #slogan section article p',{ignore:{span:true}});
    

    【讨论】:

      【解决方案2】:

      small 类实际上是由后代&lt;span&gt; 元素公开的,而不是由&lt;p&gt; 元素公开的。

      尝试使用:has() 选择器:

      Cufon.replace("#slogan section article p:not(:has(.small))");
      

      再想一想,这将忽略包含与.small 匹配的元素的&lt;p&gt; 元素,这可能不是您想要的。指定 ignoreClass 选项似乎是一个更好的主意:

      Cufon.replace("#slogan section article p", {
          ignoreClass: "small"
      });
      

      【讨论】:

      • 我也尝试过这种方式,但它排除了所有第三段。然后我也以这种方式尝试了Cufon.exclude('#main #slogan section article p .small');,但结果没有改变。
      • 我认为错误是选择了最后一个全部'p',而我必须排除的元素只是标签'span'。
      • 我认为这是因为Cufon转换了匹配元素的全部内容,包括后代,但不能排除这些后代。 ignoreClassexclude() 都不起作用似乎表明...
      • 我使用了这个方法:Cufon.replace(['#header ul.primary:eq(0) &gt; li &gt; a','#main #slogan section article p'],{ignore:{span:true}}); 现在它正在工作。这不是很好,但至少它有效。
      • @Matteo,它将忽略所有 &lt;span&gt; 元素,但在您的特定情况下可能不会对此产生不利影响。我建议您在自己的答案中发布您的解决方案,然后在 48 小时延迟结束时接受它以解决您的问题。干杯:)
      猜你喜欢
      • 2013-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多