如何在JavaScript中调用jQuery中的函数 [英] how to call function in jquery from javascript

查看:108
本文介绍了如何在JavaScript中调用jQuery中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < script type =text / javascriptsrc =jscripts / jquery.js>< / script> 

< script type =text / javascript>
$(document).ready(function(){
alert(funciton);
$(function(){
$ .fn.gotof(){
alert(我正在调用表单jquery);
}
});
});
< / script>


< input type =buttononclick =dofunc();>

< script type =text / javascript>
函数dofunc(){
gotof();
}
< / script>

我如何调用 gotof()存在于jquery
中,并且以下是通过 jsfiddle

编写的代码

解决方案

您的代码中存在一些错误。修正它应该看起来像这样:

$ $ p $ $。fn.gotof = function(){//必须被定义为一个函数,不需要在嵌套文档就绪函数中
alert(我正在调用表单jquery);
};
$ b $(document).ready(function(){
alert(函数可以立即使用);
});

函数dofunc(){
$ .fn.gotof(); //可以使用$ .fn.gotof()调用它,但应该通过选择器$('div')真正调用它。gotof();
}

http://jsfiddle.net/pSJL4/8/


<script type="text/javascript" src="jscripts/jquery.js"></script>

<script type="text/javascript">
$(document).ready(function(){
alert("funciton");
    $(function(){
        $.fn.gotof(){
            alert("I am calling form jquery");
        }           
    });
});
</script>


<input type="button" onclick="dofunc();">

<script type="text/javascript">
    function dofunc(){
        gotof();
    }
</script>

how do i call gotof() that is present in jquery and below is the code written over jsfiddle

解决方案

There are a few errors in your code. Fixed it should look like this:

$.fn.gotof = function() { // has to be defined as a function, does not need to be inside a nested document ready function
    alert("I am calling form jquery");
};

$(document).ready(function() {
    alert("function is ready to use now");
});

function dofunc() {
    $.fn.gotof();  // can call it using $.fn.gotof(), but it should really be called properly via a selector $('div').gotof();
}

http://jsfiddle.net/pSJL4/8/

这篇关于如何在JavaScript中调用jQuery中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆