jQuery 将 Link 文本替换为显示和隐藏
jQuery Replace Link Text with Show and Hide
我正在尝试使用 jQuery.
将一些 'Show More' link 文本更改为 'Show Less'
我有 created a jsfiddle 来说明我到目前为止所做的事情。我还需要在单击 'Show Less' link.
时关闭内容
jQuery(function(){
jQuery('.reveal_more').click(function(){
jQuery('.box').hide();
jQuery('#item-'+jQuery(this).attr('target')).show();
});
});
我想知道是否有人可以帮助我? :)
您可以使用.text(function)
to set text of your anchor element and based on its text value you can show/hide target using .toggle( boolean)
代码
jQuery('.reveal_more').click(function(){
jQuery('.box').hide();
//Switch text
$(this).text(function(_, val){
return val == "Show More" ? "Show Less" : "Show More"
});
//Toogle target element
jQuery('#item-'+jQuery(this).attr('target')).toggle($(this).text() == "Show Less");
});
我正在尝试使用 jQuery.
将一些 'Show More' link 文本更改为 'Show Less'我有 created a jsfiddle 来说明我到目前为止所做的事情。我还需要在单击 'Show Less' link.
时关闭内容jQuery(function(){
jQuery('.reveal_more').click(function(){
jQuery('.box').hide();
jQuery('#item-'+jQuery(this).attr('target')).show();
});
});
我想知道是否有人可以帮助我? :)
您可以使用.text(function)
to set text of your anchor element and based on its text value you can show/hide target using .toggle( boolean)
代码
jQuery('.reveal_more').click(function(){
jQuery('.box').hide();
//Switch text
$(this).text(function(_, val){
return val == "Show More" ? "Show Less" : "Show More"
});
//Toogle target element
jQuery('#item-'+jQuery(this).attr('target')).toggle($(this).text() == "Show Less");
});