首页  >  问答  >  正文

为什么return false 了 还是会跳转

<script>      // Ajax      let btn = document.getElementById("submit");      btn.onclick = function () {        //new一个ajax对象        let xhr = new XMLHttpRequest();        // 监视        xhr.onreadystatechange = function () {          // 发送成功 并且 成功收到服务器          if (xhr.readyState == 4 && xhr.status == 200) {            console.log(xhr.responseText);            // 解析返回的json字符串;            // let json = JSON.parse(xhr.responseText);            // 写入html中;            // let tips = document.getElementById("tips");            // tips.innerHTML = "欢迎用户" + json.name + "再次回来";          }        };        let name = document.getElementById("username").value;        let psd = document.getElementById("password").value;        // 生成url地址        let url = "check.php?name=" + username + "&password=" + password;        xhr.open("get", url, true);        // 传回浏览器        xhr.send(null);        return false; //去除默认提交      };    </script>

P粉751989631P粉751989631674 天前582

全部回复(0)我来回复

暂无回复
  • 取消回复