Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

我在common.js中定义了函数test,这个函数调用了a.html页面里的函数myfunc,打开a.html时提示函数未定义,怎么回事?
为什么不直接在a.html里运行myfunc() ? 我有一些逻辑上无法避免的问题,以下代码是简略了。

common.js

function test() {
    myfunc();
}

a.html

<script type="text/javascript" src="common.js></script>

<div id="c"></div>
<script>
    function myfunc() {
        $('#c').html('data');
    }
    test();
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
303 views
Welcome To Ask or Share your Answers For Others

1 Answer

common.js需要在html的js之前引入


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...