2012-10-12 72 views
0

我有代码检查所有的复选框,并添加或删除检查状态(这部分工作)。从“全选”到“全部取消”单击此功能时,我需要更改文本。 按钮选择所有:jQuery - 文本替换字符串

<a class="zute_strane_izmena_selektuj_sve">Select All</a> 

jQuery代码:

var selektuj_sve = $('.zute_strane_izmena_selektuj_sve'), 
slike = $('.zuta_strana_trenutne_slike'), 
box = slike.find(':checkbox'); 

selektuj_sve.on('click', function(){ 
    box.attr('checked', !box.is(':checked')); 
}); 

我需要做什么?

回答

3

这应该工作。

selektuj_sve.on('click', function() { 
    $(this).text(box.is(':checked') ? 'Deselect All' : 'Select All'); 
    box.attr('checked', !box.is(':checked')); 
}); 
+0

工作就像一个魅力。谢谢你帮助我:) – Sasha

+0

很高兴帮助!请不要忘记标记为已回答!谢谢! – Joshua

0
selektuj_sve.on('click', function(){ 
    box.attr('checked', !box.is(':checked')); 
    $(this).text('De-select All'); 
}); 
1

TRT这样的:

selektuj_sve.on('click', function(){ 
    box.attr('checked', !box.is(':checked')); 
    $(this).html('De-select All'); // u can use text() instead of html().. this changes the text inside to deselectAll... 
});