English 中文(简体)
我怎么说。 工作范围
原标题:How do I addclass. Working on mouseover but not on click

I am trying to get my star rater to keep the background position of the sprite I m using when clicking one of the 5 table columns inside a container div. On mouseover I m adding a style attribute to do it and that works, but when I click and add a class with the same exact css in it it doesn t effect the background position. I ve added the class by default and it still doesn t work. I guess this is really more of a css question than anything else.

Here is the code I m using: http://jsfiddle.net/cbYCZ/3/

非常感谢任何帮助。 这对我来说是一个真正的 no子。

最佳回答
问题回答

It is difficult to see exactly what is going on as your image resource (removed image path) requires authentication.

然而,我可以看到,你没有真正使用 j皮,因为它的目的是:

为取消班级,请使用<代码>。

添加和删除风格时有<条码>cs()。

添加和删除数值时有<条码>。

湿法/湿法中,有<条码>。

首先,我要改变这些问题,看问题是否继续存在。 否则,你将需要将星体描绘成某个地方的公众,以便我们能够看到你的代码。

这里的解决办法远比你大笑。 你可能发现,它以实际方式向你们教授许多更先进的技术。

我对《守则》作了相当广泛的评论。 让我知道,你是否有任何问题。

请注意,我的解决办法取决于@Abhi Beckert的关键观察,因此他应当获得接受的答复荣誉。

守则载于:。 http://jsfiddle.net/GtPnr/4/

And here is the new HTML:

<div id="rating">
    <table>
        <tr>
            <td><div id="1star" data-stars="1"></div></td>
            <td><div id="2star" data-stars="2"></div></td>
            <td><div id="3star" data-stars="3"></div></td>
            <td><div id="4star" data-stars="4"></div></td>
            <td><div id="5star" data-stars="5"></div></td>
        </tr>
    </table>
</div>
<input type="hidden" id="stars" />

我的之三者,但评论说, Java文:

// store re-used jQuery objects in variables to greatly improve performance.
// this avoids re-creating the same jQuery object every time it is used.
var $rating = $( #rating );
var $starsField = $( #stars );
// use the .hover() as a shortcut for  mouseover  and  mouseout  handlers.
$rating.find( td ).hover(function() {
    // remove all star classes then dynamically construct class name to add
    // using the data method to retrieve the value stored in the "data-stars" attribute
    // I added.
    $rating.removeClass( star1 star2 star3 star4 star5 ).addClass( star  + $(this).find( div ).first().data( stars ));
}, function() {
    // this is the mouse-out handler. Remove all star classes
    $rating.removeClass( star1 star2 star3 star4 star5 );
    // if the current value in the hidden field is set, then assign the correct class
    // so the star s clicked value is respected.
    var curVal = $starsField.val() || 0;
    if (curVal > 0) {
        $rating.addClass( star  + curVal);
    }
}).click(function() {
    // when clicking a star, store the value in the hidden input
    $starsField.val($(this).find( div ).first().data( stars ));
});




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!