[英]Script tag in view containing document.ready function is not getting hit after adding document.ready in layout page
[英]Document.Ready in Script#
獲取以下輸出JavaScript代碼的Script#語法是什么:
$(document).ready(function() {
//..my code
});
我已經嘗試過jQuery.OnDocumentReady
但是有兩個問題:
(1)只能從函數內部調用(違反了目的,因為它不會在啟動時被調用)(2) 它生成以下代碼,這不太正確: 編輯:我的錯誤,這些是等效的
$(function() {
//..my code
});
在這里找到答案:
在script#中,靜態構造函數生成為代碼,該代碼在加載和解析腳本后立即運行
因此,代碼最終看起來像這樣:
[GlobalMethods]
static class Main
{
static Main()
{
jQuery.OnDocumentReady(new Action(delegate()
{
//..my code
}));
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.