简体   繁体   English

如何在按钮中的向下箭头和向上箭头之间切换?

[英]How can I change between arrow down and arrow up in a button?

How can I show arrow up symbol in a button? 如何在按钮中显示向上箭头符号? Respectively, I would like it to change when clicked to arrow down. 我想分别单击以向下箭头更改它。 How can I do that?? 我怎样才能做到这一点??

I tried this but .... 我尝试了这个但是....

<button onclick="sortTable(1)" id="up_down" type="button" class="button button2">Sort table<i class="fa fa-fw fa-sort-asc"></i></button>

I am using the latest font awesome documentation, I could not see fa-sort-asc so instead I use fa-sort-up . 我正在使用最新的字体真棒文档,我看不到fa-sort-asc所以我改用fa-sort-up

function sortTable() {
  const ascending = false; // change the value to your sorting method to check if it's ascending or descending.
  const i = document.getElementById("up_down").getElementsByTagName("i")[0]
  i.classList.remove("fa-sort-up", "fa-sort-down");
  if (ascending) {
    i.classList.add('fa-sort-up');
    return;
  }

  i.classList.add('fa-sort-down');
}

Fiddle: https://jsfiddle.net/k6bxyps3/ 小提琴: https : //jsfiddle.net/k6bxyps3/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在按钮单击中更改向上箭头和向下箭头 - How to change up-arrow and down-arrow in button click 我无法在Textarea中禁用向上/向下箭头 - I can't Disable the Arrow up/arrow down in Textarea Svelte:按向上箭头和向下箭头键时,如何将焦点设置到列表项中的上一个/下一个元素? - Svelte: How can I set the focus to the previous/next element in the list item when pressing UP arrow and DOWN arrow keys? 如何使用箭头键在页面上的对象之间平滑上下滚动? - How can one smooth scroll up and down between objects on a page with arrow keys? 如何使用箭头键在网格中的行之间向上/向下移动图像? (JavaScript) - How do I move an image Up/Down between rows in a grid using arrow keys? (JavaScript) 通过js上下更改手风琴箭头 - Change accordion arrow up down via js 如何在按“向上”或“向下”箭头键时使Fancybox切换到下一个或上一个画廊? - How can I make Fancybox switch to the next or previous gallery upon pressing the 'up' or 'down' arrow keys? 如何将向上/向下箭头键“映射”到 Tab/Shift Tab? - How can I "Map" the up/down arrow keys to Tab/Shift Tab? Angular:使用方向键上下导航时,如何防止滚动条移动? - Angular: How can I prevent the scrollbar from moving when navigating with the arrow keys up and down? 如何根据位置更改粘性向上箭头按钮的属性? - How to change the properties of a sticky up arrow button based on its position?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM