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

新手上路,请多包涵

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);
        }
        
    }        
阅读 1.3k
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);
    } 
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题