html页面之间跳转失败,js跳转到上一页面失败的解决方法

解决方法:

只能想办法记录到页面回传的次数N了,然后使用history.go(-n),便可以回到a.html页面了。

这里强高一下history.go(-n),可以灵活控制跳转回页面的次数哦。

在b.aspx页面中放一个控件记录其回传的次数,初始值为1。

复制代码 代码示例:

function goto() {

var n=document.getElementById("TextBox1").value;

var n=Number(n);

history.go(-n);

}

1

页面b.aspx代码:

复制代码 代码示例:

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

this.TextBox1.Text = "1";

}

else

{

this.TextBox1.Text = Convert.ToString(Convert.ToInt16(this.TextBox1.Text) + 1);

}

}

这样,无论怎样操作,点返回时都可以返回a.html了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的登录界面的 HTML 代码,包含用户名、密码和登录按钮,并且在登录成功后跳转到其他页面: ```html <!DOCTYPE html> <html> <head> <title>登录</title> <meta charset="utf-8"> <style> body { background-color: #f5f5f5; font-family: Arial, sans-serif; } h1 { text-align: center; margin-top: 50px; } form { width: 300px; margin: 0 auto; background-color: #fff; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 5px; } label { display: block; margin-bottom: 10px; } input[type="text"], input[type="password"] { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 3px; font-size: 16px; margin-bottom: 20px; box-sizing: border-box; } input[type="submit"] { background-color: #4CAF50; color: #fff; border: none; padding: 10px 20px; font-size: 16px; border-radius: 3px; cursor: pointer; transition: background-color 0.3s ease; } input[type="submit"]:hover { background-color: #3e8e41; } </style> </head> <body> <h1>登录</h1> <form id="login-form" action="http://example.com/login" method="post"> <label for="username">用户名:</label> <input type="text" id="username" name="username" required> <label for="password">密码:</label> <input type="password" id="password" name="password" required> <input type="submit" value="登录"> </form> <script> // 获取表单元素和提交地址 const form = document.getElementById('login-form'); const action = form.action; // 监听表单提交事件 form.addEventListener('submit', function(event) { event.preventDefault(); // 阻止表单默认提交行为 // 发送 AJAX 请求 const xhr = new XMLHttpRequest(); xhr.open('POST', action); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { alert('登录成功!'); window.location.href = 'http://example.com/other-page'; // 跳转到其他页面 } else { alert('登录失败!'); } }; xhr.send(new FormData(form)); }); </script> </body> </html> ``` 这个登录界面使用了 HTML、CSS 和 JavaScript,采用了简洁的扁平化设计风格,使用了表单元素来实现输入框和登录按钮,同时添加了一些简单的样式来美化界面。在表单提交时,通过 AJAX 发送请求到远程服务器,如果服务器返回状态码为 200,则表示登录成功,此时通过 `window.location.href` 跳转到其他页面。你可以根据需要进行修改和完善。注意,这里的 `action` 属性需要设置为远程服务器的登录接口地址。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值