Home > Web Front-end > JS Tutorial > body text

Talk about the understanding of jquery ui tabs_jquery

WBOY
Release: 2016-05-16 15:31:36
Original
1078 people have browsed it

jquery ui click here to download , you can also go to the official website to view documentation help.

1 attribute

1.11 ajaxOptions, add an ajax option when the tab loads content. The added ajax option only works when using ajax. The default value is null. In the above example, two options, beforeSend and success, are added. There are some other options for ajax, please refer to jquery ajax, which will not be explained in detail here. . .

1.12 Initialization setting example: Please note that $('.selector') is the class name of tabs. In this example, .selector=#tabs will not be explained again.

$('.selector').tabs({ ajaxOptions: { async: false } }); //Here, asynchronous is changed to synchronous.

1.13 Parameter acquisition and setting after initialization: Please note: getter means acquisition, pronounced as: Getter, setter means setting, pronounced as: Setter, which will not be explained in the future.

//getter
var ajaxOptions = $('.selector').tabs('option', 'ajaxOptions');
//setter
$('.selector').tabs('option', 'ajaxOptions', { async: false });
Copy after login

1.21 cache defaults to false, no cache. This option is used for ajax calls. Simply put, no cache means it will be refreshed every time a request is sent; with cache, it will be refreshed on the first request and will not be refreshed in the future. Closing the page is another matter.

ajaxOptions:{cache:false} should have the same function as this.

1.22 Initialization setting example:

Copy code The code is as follows:

$('.selector').tabs({ cache: true });

2.23 Parameter acquisition and setting after initialization:

//getter
var cache = $('.selector').tabs('option', 'cache');
//setter
$('.selector').tabs('option', 'cache', true);
Copy after login

1.31collapsible, which means foldable. The default option is false and cannot be folded. If set to true, allows the user to collapse the contents of the selected tab. Let’s put it this way: Click Tab 2 once, and the content of Tab 2 is displayed. At this time, click Tab 2 again, and the content area of ​​the tab is collapsed. Click Tab 2 again, and the content area of ​​the tab is expanded again. . Do you understand? I know you don’t understand. If you don’t understand, just try the example above.

1.32 Initialization setting example:

Copy code The code is as follows:

$('.selector').tabs({ collapsible: true });

1.33 Parameter acquisition and setting after initialization: please refer to 1.23...

1.41 cookie default value is null, cookie plug-in is required. Save the last selected tab to a cookie. Examples of available options: (example): { expires: 7, path: '/', domain: 'jquery.com', secure: true }.

1.42 Initialization setting example: $('.selector').tabs({ cookie: { expires: 30 } });

1.43 Parameter acquisition and setting after initialization: please refer to 1.23...

1.51deselectable defaults to false and seems to have the same effect as collapsible.

1.61 disabled sets which tabs are unavailable. It is an array example [0,1,2], which is the first, second, and third tabs. The default is [].

1.62 Initialization setting example: $('.selector').tabs({ disabled: [1, 2] });

1.63 Parameter acquisition and setting after initialization: please refer to 1.23...

1.71 event, the event for switching tabs, the default is 'click', click to switch tabs.

1.72 Initialization setting example: $('.selector').tabs({ event: 'mouseover' }); //Switch tabs by sliding the mouse over

1.73 Parameter acquisition and setting after initialization: please refer to 1.23...

1.81 fx, animation effect when switching tabs, default: null, no animation effect,

1.82 Initialization settings: Please see the top example.

1.83 Parameter acquisition and setting after initialization: please refer to 1.23...

1.91 idPrefix, when using ajax, the idPrefix option can add a unique id to it, the default is: 'ui-tabs-'.

1.92 Initialization setting example: $('.selector').tabs({ idPrefix: 'ui-tabs-primary' });

1.93 Parameter acquisition and setting after initialization: please refer to 1.23...

1.101 selected, during initialization, which tab is selected, the default is 0, which means the first tab is selected.

1.102 Initialization setting example: $('.selector').tabs({ selected: 3 });

1.103 Parameter acquisition and setting after initialization: please refer to 1.23...

1.111 spinner, when the remote content is loaded, (ajax), the html content of the spinner string will be displayed on the title of the tab. (I’m very surprised, I tried it myself, why doesn’t it work?)

1.112 Initialization setting example: $('.selector').tabs({ spinner: 'Retrieving data...' });

1.113 Parameter acquisition and setting after initialization: please refer to 1.23...

1.121 panelTemplate ,

1.131 tabTemplate ,

2 Events

First give an example of event binding, please note:

$('#example').bind('tabsselect', function(event, ui) {
  ui.tab   // 被选中(点击后)的选项卡元素
  ui.panel  //这个元素包含被选中(点击后)的选项卡的内容
  ui.index  //返回一个被选中(或点击后)选项卡的索引值(从0开始)
});
Copy after login

2.11 select 类型:tabsselect ,点击选项卡时触发该事件。

2.12 初始化时绑定事件:

$('.selector').tabs({
  select: function(event, ui) { ... }
});
Copy after login

2.13 在初始化后使用事件绑定绑定该事件:

$('.selector').bind('tabsselect', function(event, ui) {
...
});
Copy after login

2.21 load,类型:tabsload 一个远程(ajax)选项卡的内容被加载完成后触发该事件。

2.22 参考2.12

2.23 参考2.13

2.31 show,类型:tabsshow 当选项卡显示后触发该事件。

2.41 add,类型:tabsadd ,当一个选项卡被添加后触发。

2.51 remove ,类型tabsremove ,当一个选项卡被删除后触发。

2.61 enable ,类型tabsenable ,当一个选项卡可用时触发。

2.71 disable,类型tabsdisable,当一个选项卡不可用时触发。

3 方法

3.11 destroy,哈哈,又到了我最喜欢的摧毁地球时间。例:.tabs( 'destroy' )

3.21 disable,整个选项卡不可用。

3.31 enable,整个选项卡可用。.tabs( 'enable' )

3.41 option,设置属性。例:.tabs( 'option' , optionName , [value] )

3.51 add,remove,添加、删除选项卡。例:.tabs( 'add' , url , label , [index] ) ,.tabs( 'remove' , index )

3.61 enable,设置某个选项卡标签可用。例:.tabs( 'enable' , index )

3.71 disable,设置某个选项卡标签不可用。例:.tabs( 'disable' , index )

3.81 select,选择一个选项卡标签。例:.tabs( 'select' , index ) ,index从0开始。

3.91 load,重载一个ajax选项卡的内容,这个一直载入远程内容,即使cache设置为true,第二个参数是要重载选项卡的索引值。

例:.tabs( 'load' , index )

3.101 url,当一个ajax选项卡将要加载时,改变url。.tabs( 'url' , index , url )

3.111 abort,中止所有运行在tab标签上的ajax请求或动画。.tabs( 'abort' )

3.121 rotate, 自动翻滚选项卡标签。.tabs('rotate',ms,[countinue]),第二个参数是毫秒,是两个标签自动翻滚所需要的时间,设为0或null为停止翻滚。第三个参数是设置当用户选择一个

选项卡标签后是否继续翻滚,默认为:false,不继续。

真累,歇歇再说吧。。。

4 技巧

4.1 如何接收已选中选项卡标签的索引值?

例:

var $tabs = $('#example').tabs();
var selected = $tabs.tabs('option', 'selected'); // => 0
Copy after login

4.2 如何用一个其它元素代替选项卡单击事件来切换选项卡?

例:

var $tabs = $('#example').tabs(); // 第一个标签被选中
$('#my-text-link').click(function() { // 绑定单击事件
  $tabs.tabs('select', 2); // 切换到第三个选项卡标签
  return false;
});
Copy after login

4.3 如何立刻选择刚添加的选项卡标签?

例:

var $tabs = $('#example').tabs({
  add: function(event, ui) {
    $tabs.tabs('select', '#' + ui.panel.id);
  }
});
Copy after login

4.4 如何在一个新窗口中打开选项卡标签?

例:$('#example').tabs({

  select: function(event, ui) {
    location.href = $.data(ui.tab, 'load.tabs');
    return false;
  }
});
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template