<button type="submit">提交</button> 提交后跳转页面要怎么改一下
时间: 2023-10-31 12:04:41 浏览: 37
您可以使用JavaScript在提交按钮上添加一个事件监听器,以在单击按钮时执行一些操作(例如,更改窗口位置或打开新页面)。以下是一个简单的示例:
HTML代码:
<button type="submit" id="submit-btn">提交</button>
JavaScript代码:
document.getElementById("submit-btn").addEventListener("click", function() {
// 这里添加您要执行的代码
window.location.href = "https://www.example.com/new-page.html"; // 跳转到新页面
});
相关问题
<!DOCTYPE html> <html> <head> <title>Login</title> </head> <body> <h1>Login</h1> <form action="/login" method="post"> <label for="username">Username:</label> <input type="text" id="username" name="username"><br><br> <label for="password">Password:</label> <input type="password" id="password" name="password"><br><br> <input type="submit" value="Submit"> </form> </body> </html> 增加取消按钮
要在上述代码中添加一个取消按钮,可以在 `<form>` 标签的后面插入一个 `<input>` 标签。以下是修改后的代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form action="/login" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Submit">
<input type="button" value="Cancel" onclick="window.location.href='/cancel'">
</form>
</body>
</html>
```
在上述代码中,我们添加了一个 `<input>` 标签,类型为 "button",值为 "Cancel"。同时,我们为该按钮添加了一个 `onclick` 事件,当点击该按钮时,会跳转到 "/cancel" 页面。你可以根据需要修改跳转页面的 URL。
怎么修改这段代码使点击submit按钮后跳转到下一页之前弹出等待框<form action="/login",method="get"> <div class="item"> <input type="text" name="nm"> <label for="">用户ID</label> </div> <button type="submit" class="btn">submit <span></span> <span></span> <span></span> <span></span> </button> </form>
你可以使用 JavaScript 实现这个功能,具体做法如下:
1. 在 HTML 文件中引入一个 CSS 文件和一个 JavaScript 文件。
```
<link rel="stylesheet" href="path/to/loading.css">
<script src="path/to/loading.js"></script>
```
2. 在表单中加入一个 ID,方便在 JavaScript 中调用。
```
<form action="/login" method="get" id="login-form">
<div class="item">
<input type="text" name="nm">
<label for="">用户ID</label>
</div>
<button type="submit" class="btn">submit <span></span> <span></span> <span></span> <span></span> </button>
</form>
```
3. 在 JavaScript 文件中,绑定表单的提交事件。
```
const form = document.getElementById('login-form');
form.addEventListener('submit', function(event) {
event.preventDefault(); // 阻止表单默认提交行为
const loading = createLoading(); // 创建等待框
document.body.appendChild(loading); // 将等待框添加到页面中
setTimeout(function() {
form.submit(); // 提交表单
}, 2000); // 在两秒后提交表单,模拟等待效果
});
```
4. 定义一个函数,用于创建等待框。
```
function createLoading() {
const loading = document.createElement('div');
loading.classList.add('loading');
return loading;
}
```
5. 在 CSS 文件中定义等待框的样式。
```
.loading {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
}
.loading:after {
content: "";
width: 60px;
height: 60px;
border-radius: 50%;
border: 6px solid #fff;
border-color: #fff transparent #fff transparent;
animation: loading 1.2s linear infinite;
}
@keyframes loading {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
```
这样,当用户点击提交按钮时,就会弹出一个等待框,等待两秒后再提交表单,期间用户可以看到等待框。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
新闻发布系统>>新闻管理>>查询新闻 <form action="SelectNews" method="post"> 请输入查询条件:<input type="text" name="key"> <input type="submit" value="查询"> </form>
编号 标题 类型 发布人 发布日期 状态 是否头条 操作 <c:forEach items="${newsList }" var="news"> <input type="checkbox" name="newsIds" value="${news.nid}"> ${news.nid } ${news.title } ${news.type } ${news.userName } ${news.pubtime } adadada <c:choose> <c:when test="${news.state==0 }">待审核</c:when> <c:when test="${news.state==1 }">通过</c:when> <c:otherwise>未通过</c:otherwise> </c:choose> <c:choose> <c:when test="${news.top==0 }">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> ${news.top==0?"是":"否" } 查看 <c:if test="${user.rule==0 || user.uid ==news.uid }"> 修改 </c:if> <c:if test="${user.rule==0 }"> 删除 </c:if> <c:if test="${user.rule==0 }"> 审核</c:if> </c:forEach> <c:if test="${user.rule==0}"> <button type="button">批量删除</button> </c:if> </body> <script type="text/javascript"> function banchDelete(){ var idsArray = document.getElementsByName("newsIds"); var nidArray=[];//用于存储需要删除的新闻编号 for(k in idsArray){ if(idsArray[k].checked){ nidArray.push(idsArray[k].value); } } if(nidArray.length==0){ alert("请选择要删除的新闻"); return } window.location.href="./newsBanchDelete.jsp?nids="+nidArray.join(",");//window.location.href 方法是javascript的页面跳转代码 } </script>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<title>更新汽车等级</title> <body> <main> 修改汽车等级 <form id="saveForm"> <input type="hidden" name="id" value="${data.id }"> <label>汽车等级</label> <input type="text" name="cname" value="${data.cname }" class="form-control"> </form> <button type="button" id="save" class="btn btn-primary">确定提交</button> 返回 </main> </main> <script> $("#save").click(function() { $.ajax({ cache : true, type : "post", url : "CategoryServlet?action=updateCategory", data : $("#saveForm").serialize(), async : false, success : function(e) { if (e == 'yes') { alert("修改成功!"); window.parent.location.href = "CategoryServlet?action=CategoryList"; } else { alert("修改失败!"); } } }) }); </script> </body> </html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)