簡體   English   中英

在另一個jquery或javascript函數內調用jquery document.ready函數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM