English 中文(简体)
何时工作顺序?
原标题:When does function order matter?

我的理解是,联合材料在执行守则之前,先完成各项职能。 因此,职能命令无关紧要。 但是,职能命令在将*.js文档连接起来时就成为一个问题。

For example,

<script src="@Url.Content("~/Scripts/Personal/MyJScript.js")" type="text/javascript"></script>


<script type="text/javascript">
    $(document).ready(function () {
        hello();
        afterCall();
        hello2(); //fails, defined in MyJScript2.js

    });

    function afterCall() {
        alert( inline function defined after call );
    }
</script>

<script src="@Url.Content("~/Scripts/Personal/MyJScript2.js")" type="text/javascript"></script>

在上述代码中,功能代码>>的定义是在要求确定后与之有关联的档案中。 这一呼吁失败了。 因此,现在,我直言而喻,在这一案件中担任了does号令。

Considering I perform $(document).ready, the document should be as ready as it gets. So, why does this happen?


As requested, here is the client side HTML
<body>
    <script src="/Scripts/Personal/MyJScript.js" type="text/javascript"></script>


<script type="text/javascript">
    $(document).ready(function () {
        hello();
        afterCall();
        hello2(); //fails

    });

    function afterCall() {
        alert( inline function defined after call );
    }
</script>

<script src="/Scripts/Personal/MyJScript2.js" type="text/javascript"></script>

</body>
最佳回答

我认为,问题不是顺序,而是(文件)美元。 在交回js内容之前,即可执行,因此,该功能的仓储在接获时尚未装满。

准备的文件旨在保证人力部的编写,而不是所有网上电话都填写完毕,我相当确信,通常的封条的封套在这种情况下不适用。

For what it s worth, I recreated your test and ran it successfully, proving the order doesn t matter and that this is a timing/loading issue: http://havenshade.com/tmp/testalert.html

我没有找到一个好的解决办法:

问题回答

在完成对外部联合材料档案的补充要求之前,可能要执行(或试图执行)文件夹。

It s less an issue of function declaration order than load order and timing.

您不使用文字标签进口MyJscript2,而是可使用getgust/a>,以复制文字,并在成功呼吁中履行一些功能。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签