需要合作伙伴联系我,VX(绿泡泡): w6668263      email:ye583025823@126.com

JavaScript单独的模块中传递数据

首先我们来看看这张图,让我们来思考一下!

下买我给出我的完整思路代码

html代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
<input type="button" value="button1" id="button1" />
<input type="button" value="button2" id="button2" />
<script src="https://cdn.bootcss.com/jquery/1.8.1/jquery.min.js"></script>
<script src="test1.js"></script>
</body>
</html>

 

test1.js代码

(function ($) {

    var userName = "用户名称2";

    function getEntity() {
        alert(userName);
    }

    $('#button1').click(function () {
        refFun(getEntity);
    })


})(jQuery);



(function ($) {

    var userName = "用户名称1"

    function getEntity() {
        alert(userName);
    }

    $('#button2').click(function () {
        refFun(getEntity);
    })


})(jQuery);

function refFun(fnName) {
    if (typeof fnName == "function") {
        fnName();
    }
}

 

 

 

如果这篇文章对您有帮助,您可以打赏我

 

技术交流QQ群:15129679

 
 
 
 

posted on 2019-04-11 14:37  龙行龘龘9527  阅读(262)  评论(0编辑  收藏  举报

导航