-1

Javascript没有触发的任何原因?

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script type="text/javascript">

function ChangeDisplay() 
{
    alert("Changing");

    document.getElementById('warningDiv').innerHTML = "<h1>Change Text</h1>";
    setTimeout(finalize,6000); 
} 

function finalize() 
{ 
    alert("Done");
    document.getElementById('warningDiv').innerHTML="<h1>Done</h1>"; 
}​
</script>

<h2>
    Welcome to ASP.NET!
</h2>
<p>
    <div id="warningDiv">Hello World</div>
    ​
</p>
<script>
    window.onload = setTimeout(ChangeDisplay, 3000); 
</script>

4

2 回答 2

3

Javascript没有触发的任何原因?

是的,WarnTheUser不存在并且其他函数没有被调用。

编辑:也许这是一个浏览器问题,你可以使用 jQuery,也许它会有所作为:

$(document).ready(function() { setTimeout(ChangeDisplay, 3000) });

或者

$(window).load(function() { setTimeout(ChangeDisplay, 3000) });

我不认为这是一个 ASP.NET 问题。无论如何,您还没有展示太多 ASP.NET 代码,您使用的是 Ajax 吗?

于 2012-05-11T23:49:40.623 回答
0

SOLUTION

Well, it seems that

<script type="text/javascript">    
   window.onload = setTimeout(ChangeDisplay(), 3000); 
</script>

does work, so THANKS ALL for the various tips.

All ...minus the one that did the "-1" on the post.
Never understood why people do that.

于 2012-05-12T00:34:27.553 回答