用javascript调用类-什么也不发生

用javascript调用类-什么也不发生,javascript,jquery,html,Javascript,Jquery,Html,我正在用javascript构建一个明星评级系统。我试图访问php页面中的类名。理想情况下,它会使鼠标上方的星星变色,但我这样做的时候什么也没发生 jQuery: $(document).ready(function() { // put all your jQuery goodness in here. $(function(){ $('.star').mouseover(function (

我正在用javascript构建一个明星评级系统。我试图访问php页面中的类名。理想情况下,它会使鼠标上方的星星变色,但我这样做的时候什么也没发生

jQuery:

$(document).ready(function() {
    // put all your jQuery goodness in here.



                            $(function(){
                $('.star').mouseover(function (){
                    var star = $(this).index() 1;
                    $(this).parent().css("background-position","0 -" (32 * star) "px");
                });

                $('.star-rating').mouseout(function (){
                    var originalresult = $(this).attr('id').split('result')[1];
                    $(this).css("background-position","0 -" (32 * originalresult) "px");
                });
            });​
});
html:


0 (0)


试试这个,你有一些语法错误。没有背景很难测试。查看代码a,必要时进行修改。

使用jquery更新css时,请使用
backgroundPosition
而不是
backgroundPosition
。它适用于每个css命令

$('.star').mouseover(function (){
            var star = $(this).index() 1;
            $(this).parent().css("backgroundPosition","0 -" + (32 * star) + "px");
            });

            $('.star-rating').mouseout(function (){
            var originalresult = $(this).attr('id').split('result')[1];
            $(this).css("backgroundPosition","0 -" + (32 * originalresult) + "px");
           }); 

在组成字符串时,需要添加“+”,背景位置应该是backgroundPosition。

在查看小提琴并添加带有图像的css后,它的工作方式与预期的一样。我确实注意到,当你尝试添加这个服务器端时,出于某种原因,我不断得到额外的字符,甚至当我从fiddle复制并粘贴到记事本上,然后放入我的文档时,它似乎没有任何额外的空格或字符,但一旦它在服务器上,我在jquery代码的末尾得到了3个额外的字符。我在服务器上编辑了这个文件,删除了3个额外的字符,使用了小提琴中提供的代码,效果非常好。也许只是我这边的一个错误,但这可能是你的经历

-新的工作示例

希望这对你有所帮助,因为你的帖子帮助我解决了我这边的问题,祝你好运。。。css在下面,所以它包含在这个线程中

css

    .star-rating {
     width:80px;
     height:16px;
     float:left;
     background:url(http://i39.tinypic.com/2cntjsl.png);
     cursor:pointer;
     }
     .star {
     width:16px;
     height:16px;
     float:left;
     }
     .result {
     float:left;
     height:16px;
     color:#454545;
     margin-left:5px;
     line-height:110%;
     }

我会在你的标签中包含框架。。。这看起来像jquery。这对对象模式有效。在字符串中,你可以做背景位置或背景位置。@BrianByrne检查JSFIDLE链接,让我知道你的想法。
    .star-rating {
     width:80px;
     height:16px;
     float:left;
     background:url(http://i39.tinypic.com/2cntjsl.png);
     cursor:pointer;
     }
     .star {
     width:16px;
     height:16px;
     float:left;
     }
     .result {
     float:left;
     height:16px;
     color:#454545;
     margin-left:5px;
     line-height:110%;
     }