
多个form,或者多个提交按钮对应一个form都完全没有问题
不知道你是怎么做的,想达到什么效果不行的
当然,要注意的是,多个form的话,每次提交,页面只会接收到提交的那个form的值
form不可以嵌套
一个html中可以有任意多个表单。id本来就是不可以重复的,必须是一对一的。
传值的话一般都是通过表单,传递的方法分为get和post。
get适用于对安全性无要求,数据较小的情况。例如搜索的关键词。(get方法提交的数据会在url中有所体现,你可以试一下。)
post适用于对安全性要求比较高、数据比较大的情况。例如密码。
同一个页面多个表单提交地址卸载action即可
示例:
node.js服务器代码:
const app = require("express")()const server = require("http").Server(app)
server.listen(80)
app.get('/test1',function (req,res) {
let name = req.query.name
res.send(name+"您访问了test1")
})
app.get('/test2',function (req,res) {
let name = req.query.name
res.send(name+"您访问了test2")
})
网页代码:
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>表单1访问test1</h1>
<form method="get" action="http://localhost/test1">
<input type="text" placeholder="用户名" name="name">
<input type="submit" value="提交">
</form>
<h1>表单2访问test2</h1>
<form method="get" action="http://localhost/test2">
<input type="text" placeholder="用户名" name="name">
<input type="submit" value="提交">
</form>
</body>
</html>
效果:
点击第一个表单的提交
点击点二个表单的提交
代码仅供参考。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)