【问题标题】:jQUERY Star-Rating not workingjQUERY星级评分不起作用
【发布时间】:2012-12-03 19:59:41
【问题描述】:

目前我尝试在我的 wordpress 博客中添加以下星级插件:FYNEWORKS

但由于某种原因,我似乎没有工作。我对 jQuery 完全陌生,所以希望你能帮助我。

添加到标题中:

    <script type="text/javascript" src="/wp-content/themes/wordpress-naked/js/jquery.js"/>
    <script type="text/javascript" src="/wp-content/themes/wordpress-naked/js/jquery.rating.js"/>
    <script type="text/javascript" src="/wp-content/themes/wordpress-naked/js/jquery.form.js"/>
    <script type="text/javascript" src="/wp-content/themes/wordpress-naked/js/jquery.MetaData.js"/>
    <script type="text/javascript" src="/wp-content/themes/wordpress-naked/js/jquery.rating.pack.js"/>

还有在标题中:

<script type="text/javascript">
jQuery(function($){
    ('.hover-star').rating({ 
        focus: function(value, link){ 
            var tip = $('#hover-test'); 
            tip[0].data = tip[0].data || tip.html(); 
            tip.html(link.title || 'value: '+value); 
        }, 
        blur: function(value, link){ 
            var tip = $('#hover-test'); 
            $('#hover-test').html(tip[0].data || ''); 
        } 
     });
});
</script>

我的 CSS 文件:

/* jQuery.Rating Plugin CSS - http://www.fyneworks.com/jquery/star-rating/ */
div.rating-cancel,div.star-rating{float:left;width:17px;height:15px;text-indent:-999em;cursor:pointer;display:block;background:transparent;overflow:hidden;}
div.rating-cancel,div.rating-cancel a{background:url("/wp-content/themes/wordpress-naked/js/delete.gif") no-repeat 0 -16px; !important}
div.star,div.star a{background:url("/wp-content/themes/wordpress-naked/js/star.gif") no-repeat 0 0px; !important}
div.rating-cancel a,div.star-rating a{display:block;width:16px;height:100%;background-position:0 0px;border:0 !important;}
div.star-rating-on a{background-position:0 -16px!important;}
div.star-rating-hover a{background-position:0 -32px;}
/* Read Only CSS */
div.star-rating-readonly a{cursor:default !important;}
/* Partial Star CSS */
div.star-rating{background:transparent!important;overflow:hidden!important;}
/* END jQuery.Rating Plugin CSS */

我的单选按钮具有第二个代码部分“.hover-star”中定义的类。

但是,它仍然无法正常工作。是我打错字还是忽略了什么?

谢谢:)

【问题讨论】:

  • 尝试在此处添加$ $('.hover-star').rating({

标签: jquery


【解决方案1】:

您的脚本应该几乎总是在文档完全加载后启动,否则它会执行得太早而无法找到项目。

$(document).ready(function() { ... // your code // ... })

wirey 关于丢失的 $

也是正确的

【讨论】:

  • 哎呀我自己都不知道 :(
  • 现在你做 :) 这只是一个速记/快捷版本
  • 不确定是否允许,但这是我正在谈论的页面:beebo.nl/test123-2
【解决方案2】:

首先,你没有在这里调用 jQuery:

('.hover-star').rating({

您需要使用$ 或jQuery 调用jQuery:

$('.hover-star').rating({

可能还有其他问题。我建议使用调试器。这将有助于找到这个问题和其他问题。

【讨论】:

  • 添加了 $ 符号,以便 jquery 调用它。到目前为止没有运气,但我真的很感谢快速回复:)
猜你喜欢
  • 2018-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多