Jquery未捕获referenceerror:函数未定义 [英] Jquery uncaught referenceerror: function is not defined
问题描述
我遇到了这个错误,我发现它令人沮丧,因为我已经在我的旧项目中使用了这个代码并且它工作正常但是当我为我的新项目添加代码时,它显示没有像它不起作用,当我查找浏览器控制台显示错误Uncaught ReferenceError:未定义showDays。我将此代码放在select控件的onchange事件中..
以下是产生错误的代码:
I am stuck with this error and I find it frustrating because I already used this code in my old project and it's working fine but when I add the code for my new project it display nothing like it's not working and when I look up the browser console it presents the error Uncaught ReferenceError: showDays is not defined. I put this code inside the onchange event of a select control..
Here is the code that generates the error:
function showDays(str)
{
$.get("<?php echo site_url('wip/get_deliverydays');?>",{q:str},function(data){
$("#deliverydays").html(data);
});
}
我的尝试:
我尝试搜索此错误的解决方案,但他们给出了不适用于我的问题的答案。
What I have tried:
I tried searching solution for this error but they gave answers that are not applicable to my problem.
推荐答案
.get( <?php echo site_url('wip / get_deliverydays');?>,{q:str},< span class =code-keyword> function (data){
.get("<?php echo site_url('wip/get_deliverydays');?>",{q:str},function(data){
( #deliverydays)。html(data);
});
}
("#deliverydays").html(data); }); }
我的尝试:
我尝试搜索此错误的解决方案,但他们给出了不适用于我的问题的答案。
What I have tried:
I tried searching solution for this error but they gave answers that are not applicable to my problem.
这主要是范围问题。虽然定义了showDays()
函数,但由于全局范围,它无法访问。所以你需要把你的代码放在jQuery函数之外,或者你需要在jQuery函数范围内调用函数:
选项1 :放你的外部自定义功能
It is mostly scope issue. AlthoughshowDays()
function defined it is not accessible due to global scope. So you need to put your code outside jQuery function or you need to call the function inside jQuery function scope:
Option 1: Put your custom function outside
function showDays(str)
这篇关于Jquery未捕获referenceerror:函数未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!