简体   繁体   English

点击调用jQuery插件

[英]Calling jQuery Plugin on click

I have searched and searched but have not found a simple answer to why the following does not work. 我进行了搜索,但没有找到以下原因无法解决的简单答案。 What I was trying to do is call a jQuery plugin in a click event instead of at page load (doc ready). 我试图做的是在click事件中而不是在页面加载时(文档就绪)调用jQuery插件。 So, this code works: 因此,此代码有效:

<script type="text/javascript">
        $(document).ready(function() {
            $("#slidingtabs").slidingTabs({ 
                tabActive:1, 
                totalHeight:"580", 
                orientation:"vertical" 
            });
        });
    </script>

This code below does not work. 下面的代码不起作用。 I have put the same code inside a click function. 我已经将相同的代码放入click函数中。 I get no errors, but nothing happens: 我没有收到任何错误,但没有任何反应:

<script type="text/javascript">
        $(document).ready(function() {
            $("#testbutton2").click(function(){
                $("#slidingtabs").slidingTabs({ 
                tabActive:1, 
                totalHeight:"380", 
                orientation:"vertical"  
            });

                });
        });
    </script>

Can someone tell me why it doesn't work, and what I need to do to call the plugin on a click event, or a re-size window event, or equivalent? 有人可以告诉我为什么它不起作用,以及在单击事件,调整大小窗口事件或等效事件时调用插件需要做什么?

Could this be something specific to this plugin (I did not write it)? 这可能是该插件特有的(我没有写)吗?

Thank you for any help or insight. 感谢您的帮助或见解。

Sharing some of the HTML in your question would help. 共享您问题中的某些HTML会有所帮助。 I would start using chrome dev tools or firebug in firefox and run: 我将开始在Firefox中使用Chrome开发工具或Firebug并运行:

$("#testbutton2").length 

to verify you are selecting something. 确认您正在选择某项。

Then add a console.log inside your click handler to make sure that something is happenning. 然后在您的点击处理程序中添加console.log,以确保发生了某些事情。

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

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