开发者

JQuery: How to use an HTML ascii arrow for a toggle indicator?

I came across this great JQuery example of using a slidetoggle.

I want to implement it exact as is, except fo开发者_C百科r one thing.

The example uses an image for the Up and Down (white) arrow indicator.

Can't I use the HTML ascii up arrow (↑) and down arrow (↓) instead of using an image.

If so, how?


I believe something like this should work:

$(".btn-slide").click(function(){
  $("#panel").slideToggle("slow");
  $(this).toggleClass("active");

  //Toggle text here (I may have the up/down order inverted)
  $(".btn-slide").toggle(function() {
      $(this).text('Slide ↑');
    }, function() {
      $(this).text('Slide ↓');
  });
  return false;
}); 

Basically the idea is just to toggle the text on the link when it is clicked, the same place the author toggles the up/down slide.

More info on toggle() here.

You will also need to remove the white background image from here:

.btn-slide  {
background:url("images/white-arrow.gif") no-repeat scroll right -50px 

HTH


You can change the text value of the anchor element as follows.

$(".btn-slide").click(function(){  
    $("#panel").slideToggle("slow");  
    $(this).toggleClass("active"); return false;  
    $(this).text('YourText ' + ($(this).hasClass('active') ? '↑' : '↓'));
});    

Removing the arrow image is done by eliminating the CSS background property of the .btn-slide selector.


in my case, i prefer use attribute .attr()

$(this).attr('value', '↑');

When testing using firebug, i use .val() or .html(), after <input> will add extra </input>. Its not work for me.

Sorry my bad English.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜