与window.history.back()不一致 [英] Inconsistency with window.history.back()

查看:117
本文介绍了与window.history.back()不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用于测试window.history.back()的MVC视图中具有以下代码

I have the following code in an MVC view that I'm using to test window.history.back()

如果用户单击段落标记内的链接(以红色突出显示),则window.history.back()会按我期望的那样执行.我将返回上一页,并在该页面上保持状态.但是,如果用户单击该按钮,则不会得到相同的行为.重新加载当前视图,或者至少尝试重新加载当前页面.但是失败了.而且,不管是执行jQuery还是将我的window.history.back()调用放在Button onClick上都没关系,同样的事情也会发生.

If the user clicks the link (highlighted in red) within the paragraph tag, window.history.back() executes as I would expect. It takes me back to the prior page with state maintained on that page. However, if the user clicks the button, I don't get the same behavior. The current view is reloaded, or at least an attempt is made to reload the current page. But it fails. And it doesn't matter if the jQuery is executed, or I put the window.history.back() call within the Button onClick, the same thing happens.

一条可能有用的信息.该按钮位于HTML.BeginForm内部,段落标记中的行不在此.

A piece of information which might be helpful. The button is inside an HTML.BeginForm and the line in the paragraph tag is not.

有人知道为什么会这样吗?

Anyone know why this is happening?

推荐答案

浏览器可能会将按钮解释为提交"按钮并提交表单,从而导致页面刷新.添加type="button"可以防止这种情况.

The browser is probably interpreting the button as a submit button and submitting the form, thus causing a page refresh. Adding type="button" will prevent that.

<button type="button">Cancel</button>

这篇关于与window.history.back()不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆