![](/img/trans.png)
[英]Why does jQuery document.ready inside a self-invoking JavaScript function call a function defined in a different scoped function?
[英]call jquery document.ready function inside another jquery or javascript function
我正在嘗試在另一個JavaScript函數中調用document.ready()函數時遇到一個問題,但是當我調用它時,它說“函數未定義
這是我的代碼:這是第一個函數,即document.ready()函數
$(document).ready(function ExpandMessageBox() {// this is my document.ready function. I have given the name of it as "ExpandMessageBox"}
這是另一個常規的JavaScript函數,我試圖在其中調用上面的函數
function ShowMessageBox() {
ExpandMessageBox();}
但這給了我一個錯誤,如:“ Uncaught ReferenceError:未定義ExpandMessageBox”
我在哪里做錯了...請幫助
提前感謝
您需要在公共范圍內定義ExpandMessageBox
函數。 像這樣:
function ExpandMessageBox() {
//your staff
}
function ShowMessageBox() {
ExpandMessageBox();
}
$(document).ready(ExpandMessageBox);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.