JS提交表单后回跳的细节处理

JS提交表单后回跳的细节处理

编程文章jaq1232025-03-05 12:05:2728A+A-

有些时候提交表单后需要我们留在原来表单的界面,那么提交后如何使表单里面的内容清空或者保留呢?作为一个小知识点我总结了下:(以后我还会补充些相关内容)

表单里的内容我经过在servelet测试替换红色部分的内容,

        int b = new MemberDao.save(member);
        if(b!=0){
 out.print("<script>alert('提交成功')</script>");
 out.print("<script>location.href='WebPage/wyrh.jsp';</script>");
 out.print("true");
        }else{
 out.print("error");
        }

发现以下这些方法 前台表单还是会保存记录的(就是执行servelet后表单写着的内容还显示着)

window.location.reload 刷新

window.history.go(1) 前进

window.history.go(-1) 后退

window.history.forward 前进

window.history.back 相当于 window.history.go(-1)+window.location.reload

后来我查找到了前台表单不会保存记录的方法

location.href=‘’;location.assign(两者相同)

location.href='http://www.example.com'
而location.assign('http://www.example.com') 就是 location.href='http://www.example.com'
至于

还有一个类似的location.replace,但是使用它servelet返回不到前台了

location.replace('http://www.example.com')与前两者的区别是,在replace之后,浏览历史就被清空了(href与assign方法会产生历史记录)。
点击这里复制本文地址 以上内容由jaq123整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!

苍茫编程网 © All Rights Reserved.  蜀ICP备2024111239号-21