默认状态为:
<a href="./" class="dynamic dynamic-children menu-item"><span class="additional-background"><span class="menu-item-text">Présentation</span></span></a>
所以如果class = rfr-opened add alt =“open”
<a alt="open" href="./" class="dynamic dynamic-children menu-item rfr-opened"><span class="additional-background"><span class="menu-item-text">Présentation</span></span></a>
所以如果班级没有rfr-opened add alt =“close”
<a alt="closed" href="./" class="dynamic dynamic-children menu-item"><span class="additional-background"><span class="menu-item-text">Présentation</span></span></a>
答案 0 :(得分:3)
这样的东西?
$('a').attr('alt', 'closed');
$('a.rfr-opened').attr('alt', 'open');
答案 1 :(得分:1)
尝试并测试:http://jsfiddle.net/eMagu/(我使用检查器检查alt值)
jQuery one liner ...
// set all menu items to closed, then filter just the open class and set to open
$('.menu-item').attr('alt','closed').filter('.rfr-opened').attr('alt','open')
答案 2 :(得分:0)
这应该有所帮助:
$('.menu-item').each(function () {
if ($(this).hasClass('rtf-opened')) $(this).attr('alt', 'open');
else $(this).attr('alt', 'closed');
});
答案 3 :(得分:0)
我认为有些事情是这样的。 。 。
$('a.menu-item')each(function() {
if($(this).hasClass('rfr-opened')) {
$(this).attr('alt', 'open');
} else {
$(this).attr('alt', 'closed');
}
});
答案 4 :(得分:0)
这对我有用
jQuery("#rfr-topnav a").click(function () {
$('#rfr-topnav a').attr('title', 'closed');
$('#rfr-topnav a.rfr-opened').attr('title', 'open');
});