简体   繁体   English

jQuery UI选项卡javascript单击功能不起作用

[英]jQuery UI tabs javascript click function not working

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. 我正在使用另一个script.js文件。 from that I am calling one click function. 从那我叫一键式功能。

$("#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? 如何使用jQuery编写js函数? Please help me. 请帮我。

Thanks, Raj 谢谢,拉杰

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");    
});

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 希望能帮助到你

Solution given by Lorenzo is not working for me but the solution given by keith_c works like charm. Lorenzo提供的解决方案对我不起作用,但是keith_c提供的解决方案就像魅力一样工作。 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 我确实找到了另一种方法来满足此要求,因为我很难在这里放置代码,您可以在http://ektaraval.blogspot.com/2011/09/calling-javascript-when上进行查看-jquery-ui-tab.html

Hope that helps someone.. 希望能帮助到某人..

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM