jQuery UI 选项卡 javascript 单击功能不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3938270/
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
jQuery UI tabs javascript click function not working
提问by Raj
I am using jQuery UI tabs, but I am having an issue.
我正在使用 jQuery UI 选项卡,但我遇到了问题。
My javascript code:
我的javascript代码:
$(function() {
$("#tabs").tabs();
});
My HTML:
我的 HTML:
<div class="demo">
<div id="tabs">
<ul>
<li><a href="#tabs-1">Eat</a></li>
</ul>
<div id="tabs-1">
tab 1
</div>
<div id="tabs-2">
tab 2
</div>
<div id="tabs-3">
tab 3
</div>
</div>
</div><!-- End demo -->
I am using another script.js file. from that I am calling one click function.
我正在使用另一个 script.js 文件。从那我调用一键功能。
$("#tabs-2").click(function()
{
alert("This is tab3");
});
This function is not working. I want to display some data from the database on clicking each tab. How to write js function using jQuery? Please help me.
此功能不起作用。我想在单击每个选项卡时显示数据库中的一些数据。如何使用jQuery编写js函数?请帮我。
Thanks, Raj
谢谢,拉吉
回答by keith_c
What type of error are you getting? Can you use Firebug to help debug the issue you are having w/your jQuery?
你得到什么类型的错误?您可以使用 Firebug 来帮助调试您在使用 jQuery 时遇到的问题吗?
Have you tried:
你有没有尝试过:
$("a[href=#tabs-2]").click(function()
{
alert("This is tab3");
});
回答by Lorenzo
This is the correct code you should use
这是您应该使用的正确代码
HTML:
HTML:
<div class="demo">
<div id="tabs">
<ul>
<li><a href="#tabs-1">Eat</a></li>
<li><a href="#tabs-2">Drink</a></li>
<li><a href="#tabs-3">Sleep</a></li>
</ul>
<div id="tabs-1">
tab 1
</div>
<div id="tabs-2">
tab 2
</div>
<div id="tabs-3">
tab 3
</div>
</div>
</div>
jQuery:
jQuery:
$(function() {
$("#tabs").tabs();
$("#tabs-2").click(function() {
alert("This is tab2");
});
}); ?
You can verify it working here.
您可以在此处验证它是否有效。
Hope it helps
希望能帮助到你
回答by Ekta
Solution given by Lorenzo is not working for me but the solution given by keith_c works like charm. I did find out one more way to to accomplish this requirement, as it's tough for me to put code here, you can have a look at it on http://ektaraval.blogspot.com/2011/09/calling-javascript-when-jquery-ui-tab.html
Lorenzo 给出的解决方案对我不起作用,但 keith_c 给出的解决方案就像魅力一样。我确实找到了另一种方法来完成这个要求,因为我很难把代码放在这里,你可以在http://ektaraval.blogspot.com/2011/09/calling-javascript-when上查看-jquery-ui-tab.html
Hope that helps someone..
希望能帮助某人..

