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

来源:互联网 发布:广东卫视网络电视回看 编辑:程序博客网 时间:2024/06/11 09:11

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

 

表单里的内容我经过在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方法会产生历史记录)。
0 0
原创粉丝点击