English 中文(简体)
增 编 点击时的图像级。 如果对另一个图像进行点击,则删除这一类别,并将其添加到新的形象中。
原标题:addClass to an image when clicked. If another image is clicked, remove that class and add it to the new image

我有一份载有4个图像的清单。 每个图像在任何特定时间只能有一个活跃的班级。 (相当于无线电台。)

My code so far supports this fine: http://jsfiddle.net/tctc91/HyHgp/

var themeChooser = $( .themeChooser ul li img );
themeChooser.click(function() {
    if(!themeChooser.hasClass( themeSelected )) {
        $(this).addClass( themeSelected );        
    } else {
        $(this).removeClass( themeSelected );
    }
});

我的问题是,何时。 主题班已经活跃, 如果你点击不同的形象,它就不会发挥作用。 我需要它这样做,因为国际红十字与红新月联会已经发挥了积极作用,你用不同的形象点击,它消除了现有的阶层,并增加了新的形象。

感谢!

最佳回答

简单增加<代码>$(themeS selected ).removeClass(主题S selected );,在你点击手里达到你想要达到的目的。

Live example: http://jsfiddle.net/sT9jE/


。 并非非常简单,上述内容在选定的要素上停止了重弹。 因此,你实际上需要增加:

if(!$(this).hasClass( themeSelected ))
    $( .themeSelected ).removeClass( themeSelected );

See this Live example:

问题回答

暂无回答




相关问题
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!

热门标签