jQuery Microsoft JScript 运行时错误:标签小部件实例没有这样的方法“选择”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16033490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Microsoft JScript runtime error: no such method 'select' for tabs widget instance
提问by Rajaram Shelar
I need selectspecific tab functionality for the jquery tabs on clicking on the html buttons. I am using jquery.1.9.1.js
and jquery-ui-1.10.2.custom.js
file. I have implemented below code but does not work for me.
我需要在单击 html 按钮时为 jquery 选项卡选择特定的选项卡功能。我正在使用jquery.1.9.1.js
和jquery-ui-1.10.2.custom.js
归档。我已经实现了下面的代码,但对我不起作用。
<script language="javascript" type="text/javascript">
$("#ui-tabs").tabs();
function SelectTab() { // bind click event to link
$('#ui-tabs').tabs('select', 2); // switch to third tab
return false;
}
</script>
<div id="ui-tabs">
<ul>
<li><a href="#tabs-1">Nunc tincidunt</a></li>
<li><a href="#tabs-2">Proin dolor</a></li>
<li><a href="#tabs-3">Aenean lacinia</a></li>
</ul>
<div id="tabs-1">Tab1 content </div>
<div id="tabs-2">Tab2 content </div>
<div id="tabs-3">Tab3 content </div>
</div><a id="next" class="button-style" href="#" onclick="return SelectTab();">Select Tab</a>
The problem is statement $('#ui-tabs').tabs('select', 2);
in function SelectTab
gives me error Microsoft JScript runtime error: no such method 'select' for tabs widget instance
. Normal selection of tabs on clicking on them working fine. But it is not working when done from function call. Whats going wrong in the implementation or is there any file missing? please suggest.
问题是$('#ui-tabs').tabs('select', 2);
函数中的语句SelectTab
给了我错误Microsoft JScript runtime error: no such method 'select' for tabs widget instance
。单击它们时正常选择选项卡工作正常。但是从函数调用完成时它不起作用。实施中出了什么问题,或者是否缺少任何文件?请建议。
回答by Tim B James
There is no select
method for jQuery UI Tabs in this version. To get your functionality to work you need to change your code to;
select
此版本中没有jQuery UI 选项卡的方法。要使您的功能正常工作,您需要将代码更改为;
$('#ui-tabs').tabs( "option", "active", 2 );
Please read http://api.jqueryui.com/tabs/#option-activefor more information on this.
请阅读http://api.jqueryui.com/tabs/#option-active了解更多信息。
// getter
var active = $( ".selector" ).tabs( "option", "active" );
// setter
$( ".selector" ).tabs( "option", "active", 1 );
Check out this little jsFiddlefor an example of it working.
查看这个小jsFiddle以了解它的工作示例。
回答by Max
If you want to make indiviual links to open tabs on your site you can use the function below and call it with
如果您想制作单独的链接以在您的网站上打开标签,您可以使用下面的功能并调用它
<div onclick="changeToTab(targetTabNumber)"> mylinkText </div>
function changeToTab(ID){
var $tabs = $('#tabs').tabs();
$tabs.tabs( "option", "active", ID );
return false;
}
First target is adressed with 0, second with 1 and so on. The div can be anything that allows onclick of course.
第一个目标用 0 寻址,第二个用 1 寻址,依此类推。div 可以是任何允许 onclick 当然的东西。