![](/img/trans.png)
[英]Javascript function is not getting call from code behind when it is put on master page
[英]call jQuery function from code behind at master page on page load
我在頁面加載時從我的母版頁中的代碼調用jQuery函數,它返回此錯誤:
ReferenceError:$未定義
代碼背后: -
protected void Page_Load(object sender, EventArgs e)
{
string script = "$(document).ready(function () {alert('hello'); });";
Page.ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);
}
我也試過這個jquery函數: -
ScriptManager.RegisterStartupScript(Page, typeof(Page), "ShowProgressBar", "ShowProgressBar();", true);
但后來得到錯誤“ShowProgressBar未定義”。
嘗試這個,
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Function1", "yourFunction();", true);
您錯過了加載您的jquery文件在標頭中添加以下腳本標記。
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.