清除浏览器后退按钮上的字段
问题描述:
我使用以下Javascript代码禁用了浏览器的后退按钮。 它的工作原理,但我想要一个代码,将清除我的表单上的所有领域或至少重新加载我的网页通过浏览器的后退按钮单击。我正在使用C#。清除浏览器后退按钮上的字段
任何帮助表示赞赏。谢谢。
function DisableBackButton() {
window.history.forward()
}
DisableBackButton();
window.onload = DisableBackButton;
window.onpageshow = function (evt) { if (evt.persisted) DisableBackButton() }
window.onunload = function() { void (0) }
我试图这样做。但不工作
Protected void Page_Load(object sender, EventArgs e)
{
tbPs.Text = " ";
tbName.Text = " ";
tbEmail.Text = " ";
tbContact.Text = " ";
tbSug.Text = " ";
rbTheme3.Checked = true;
rbFoodVar3.Checked = true;
rbTransport3.Checked = true;
rbLoc3.Checked = true;
rbTime3.Checked = true;
}
答
像这样做在JavaScript中unload
功能
对于文本框
$('input:text').val('');
对于复选框
$('input:checkbox').prop('checked', false);
对于选项框
var radioGroups = [];
$("input:radio").each(function(){
if (radioGroups.indexOf(this.name) > -1) { return; }
radioGroups.push(this.name);
});
radioGroups.forEach(function (groupName) {
var $group = $('input[name="' + groupName + '"]:radio');
$group.prop('checked', false);
// if you want to select the third one
$group[2] && $($group[2]).prop('checked', true);
});
答
试试这个..
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);
上面的代码将禁用页面缓存。由于该页面未被缓存在浏览器中,因此当用户点击后退按钮时,页面将被重新加载。
你的表格包含什么?文本框只?或选择框也? –
@AmmarHasan文本框和单选按钮 –
文本框可以轻松清除,但对于单选按钮,是否有任何默认值? –