如何把这段代码转化成jquery代码

  • 1
新手上路,请多包涵

function getuser() {

        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        testing(username, password)
    }

    function testing(username, password) {
        var tmp = username && password;
        if (tmp == "") {
            alert("请填写完整信息");
            
        }else{
            window.location.href = "comment.html";                
            alert("登录成功");
            localStorage.setItem("username",username);
        }
        
    }        
回复
阅读 334
2 个回答

原生的JavaScript不行吗?
如果真的转化话,这样?没有啥意义呀,具体可以看文档

function getuser() {
        // var username = document.getElementById("username").value;
        var username = $('#username').val();
         // var password = document.getElementById("password").value;
        var password = $('#password').val();
        testing(username, password)
    }

    function testing(username, password) {
        var tmp = username && password;
        if (tmp == "") {
            alert("请填写完整信息");
            
        }else{
            window.location.href = "comment.html";                
            alert("登录成功");
            localStorage.setItem("username",username);
        }
        
    }        
    let username = $('#username').val();
    let password = $('#password').val();
    if (username && password) {
        alert('请填写完整信息');
    }else{
        window.location.href = "comment.html";                
        alert("登录成功");
        localStorage.setItem("username",username);
    } 
宣传栏