Javascript 错误:未定义函数
我创建了一个具有函数的Javascript 错误:未定义函数,javascript,jquery,Javascript,Jquery,我创建了一个具有函数的js文件。 当我在$(document).ready上调用该函数时它不工作 我检查了firebug,它正在调用函数,但没有进入函数 以下是我的JavaScript代码: function toggelEventButtons() { var invoiceVal = $('#Invoice_Id').val(); //It is a textbox Id of aspx Page. alert(invoiceVal); if (invoiceVa
js
文件。当我在
$(document).ready上调用该函数时代码>它不工作
我检查了firebug,它正在调用函数,但没有进入函数
以下是我的JavaScript代码:
function toggelEventButtons() {
var invoiceVal = $('#Invoice_Id').val(); //It is a textbox Id of aspx Page.
alert(invoiceVal);
if (invoiceVal > 0) {
$('#addEventInvoiceDetail').hide();
$('#editEventInvoiceDetail').show();
} else {
$('#addEventInvoiceDetail').show();
$('#editEventInvoiceDetail').hide();
}
}
我从aspx
页面调用函数,如下所示:
$(document).ready(toggelEventButtons);
确保函数在同一作用域上。
您也可以尝试这种语法
$(document).ready(function(){ toggelEventButtons() });
在调用$(document)之前,请确保将文件包含在函数中。ready()
函数定义是在顶级还是在另一个函数中?它是独立的。不在另一个函数内。您所说的“它正在调用函数,但没有进入函数”是什么意思?请确保在调用$(document).ready()之前将文件包含在函数中。该函数位于其他js脚本上?您忘记包含它了吗?顺便说一句,因为这是问题所在,这意味着解决方案$(function(){toggelEventButtons();})代码>实际上会有所帮助。不过,这或许不是解决这个问题最简单的办法:)