JQuery里面的函数调用另一个函数= undefined? [英] JQuery inside function call another function = undefined?

查看:81
本文介绍了JQuery里面的函数调用另一个函数= undefined?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在body之前调用另一个函数,但怎么做?

系统显示错误未定义的函数myx

我只能在body之后添加代码。

 < ; script type =text / javascript> 
jQuery(function($){
function myx(){
alert(omg);
};
});
< / script>
< / head>

< body>
< script>
jQuery(document).ready(function($){
$(mytest)。click(function(){
myx();
});
});
< / script>
< a href =#id =mytest>检查< / a>


解决方案

该功能超出范围。您需要定义jQuery回调之外的函数。

 < script type =text / javascript> 
函数myx(){
alert(omg);
};
< / script>
< / head>

< body>
< script>
jQuery(document).ready(function(){
$(#mytest)。click(function(){
myx();
});
});
< / script>
< a href =#id =mytest>检查< / a>


I want to call another function before body, but how?

The system shows me the error undefined function myx

I only can add code after body.

<script type="text/javascript">
jQuery(function($){
    function myx() {
        alert("omg");
    };
});
</script>
</head>

<body>
<script>
jQuery(document).ready(function($){
    $("mytest").click(function(){
        myx();
    });
});
</script>
<a href="#" id="mytest">Check</a>

解决方案

That function is out of scope. You need to define the function outside the jQuery callback.

<script type="text/javascript">
    function myx() {
        alert("omg");
    };
</script>
</head>

<body>
<script>
jQuery(document).ready(function(){
    $("#mytest").click(function(){
        myx();
    });
});
</script>
<a href="#" id="mytest">Check</a>

这篇关于JQuery里面的函数调用另一个函数= undefined?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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