【问题标题】:How to call a function in the javascript file type="module" [duplicate]如何在 javascript 文件 type="module" 中调用函数 [重复]
【发布时间】:2021-08-07 07:08:33
【问题描述】:

我使用 .net 应用程序来设计我的网站。我导入以下文件:

//html file like:
<script src="~/js/login/login.js" type="module"></script>



//code  login.js below:
import reponsitoryfactory from "../../service/factory/reponsitoryfactory.js";
const authreponsitory = reponsitoryfactory.get("auth");

export function login() {
    alert('fasfs');
    var data = {
        "username": $('#txt-username').val(),
        "password": $('#txt-password').val()
    };
    authreponsitory.login(data).then(function (response) {
        if (response.data.success) {
            alert("success");
        }
    });
};

在 HTML 文件中,我将登录函数称为:

<span class="k t btn bnt-login" onclick="login1()">Login</span>

我尝试了一些方法来解决登录功能不存在的问题,谁能帮我在javascript文件模块中调用一个函数!

【问题讨论】:

    标签: javascript c# .net asp.net-core module


    【解决方案1】:

    您可以进行如下更改。

    //html文件如:

    <script src="~/js/login/login.js" type="module"></script>
    
    <button id="login">Login</button>
    

    //下面的代码login.js:

    import reponsitoryfactory from "../../service/factory/reponsitoryfactory.js";
    const authreponsitory = reponsitoryfactory.get("auth");
    
    export function login() {
        alert('fasfs');
        var data = {
            "username": $('#txt-username').val(),
            "password": $('#txt-password').val()
        };
        authreponsitory.login(data).then(function (response) {
            if (response.data.success) {
                alert("success");
            }
        });
    };
    document.querySelector('#login').addEventListener('click', login);    
    

    【讨论】:

    • 谢谢,有没有办法调用视图??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-17
    • 2015-06-13
    • 1970-01-01
    相关资源
    最近更新 更多