jQuery UI tabs. How to select a tab based on its id not based on index

前端 未结 14 2180
刺人心
刺人心 2020-12-25 11:07

I have two tabs and configured usign jQuery UI.

ul  class=\"tabs\"
  li  tabone
  li tabtwo
ul

dynamically from C# code behind I will hide

14条回答
  •  北海茫月
    2020-12-25 11:42

    It may have side effects if there are other listeners, and it doesn't feel as nice as interacting through the plugins API -- but it gives a less verbose code if you just "click" the tab, rather than count it's index and set it active afterwards, and it's pretty intuitive what's going on. Also it wont fail if the ui-guys decide to rename the option again.

    $('#tabs').tabs(); 
    $('#tabs a[href="#tabtwo"]').click();
    

    It's intriguing, though, that the ui tabs code has a meta-function (_getIndex) with the comment:

    "meta-function to give users option to provide a href string instead of a numerical index"

    but does not use it when setting the active option, only when calling enable, disable and load.

提交回复
热议问题