我有asp.net web站點與ajax和jquery。 我需要在兩個jquery腳本文件中使用jquery pageLoad函數,但問題在於它只在第一個附加在母版頁中的其中一個工作。jquery pageLoad()不能在多個js文件中工作
我有crated簡單的視覺stuido測試網站項目,我會很高興,如果你會下載並看到它。
我上傳它的主人MediaFire http://www.mediafire.com/?4b71u9jvo0mxru3它只是5KB請幫我有人
我有asp.net web站點與ajax和jquery。 我需要在兩個jquery腳本文件中使用jquery pageLoad函數,但問題在於它只在第一個附加在母版頁中的其中一個工作。jquery pageLoad()不能在多個js文件中工作
我有crated簡單的視覺stuido測試網站項目,我會很高興,如果你會下載並看到它。
我上傳它的主人MediaFire http://www.mediafire.com/?4b71u9jvo0mxru3它只是5KB請幫我有人
每頁只能有一個頁面加載。我下載了你的代碼,我改變了:
在MasterPage.master:
<asp:ScriptManager ID="MainScriptManager" runat="server" EnablePartialRendering="true">
<Scripts>
<asp:ScriptReference Path="~/jscript/btnFirst.js" />
<asp:ScriptReference Path="~/jscript/second.js" />
</Scripts>
</asp:ScriptManager>
而且在頭刪除此:
<script type="text/javascript" src="jscript/second.js"></script>
<script src="jscript/btnFirst.js" type="text/javascript"></script>
在btnFirst.js(例如)改變頁面加載到:
// Attach a handler to the load event.
Sys.Application.add_load(applicationLoadHandler);
function applicationLoadHandler() {
$('#btnFirst').each(function() {
$('#btnFirst').css('text-decoration', 'none');
$('#btnFirst').css('opacity', '1');
var elem = $(this);
setInterval(function() {
if (elem.css('opacity') == '1') {
elem.css('opacity', '0.1');
} else {
elem.css('opacity', '1.0');
}
}, 500);
});
};
大功告成;-)
而你真的很棒。不幸的是,我不能接受這個答案很多次:)再次感謝你 – 2012-02-09 21:22:10
而不是使用頁面加載(),你應該使用$(文件)。就緒的。這是通過將一個匿名函數傳遞給添加到隊列中的.ready()函數來實現的。 DOM加載後,所有匿名函數都會運行。
$(document).ready(function(){
// your function code here
});
不,它不適用於ajax。 – 2012-02-09 17:27:27
我的同事提出的另一種方法(感謝James)是使用自定義事件(請注意,這仍然在測試中)。
步驟1:在母版,包括以下內容作爲最後的腳本(其它腳本後):
<script type="text/javascript">
function pageLoad(sender, args) {
$(document).trigger('PartialPageLoad');
}
</script>
步驟2:在腳本文件,當您要執行的頁面加載的東西,重視到事件如下:
$(document).on('PartialPageLoad', function() {
doSomething();
doSomethingelse();
});
因爲它只能用JavaScript做你可以在jsfiddle.net上做一個例子嗎? – albertjan 2012-02-09 17:16:47
你最好上傳你的項目在github或bitbucket或任何人們可以瀏覽源代碼,而無需下載你的rar文件並在VS中打開它。 – 2012-02-09 17:24:20
the_ajp不,因爲問題只與asp有關。 ajax – 2012-02-09 17:31:05