<table id="addTableTag"> <tr> <td>商品id:<input type="text" name="shangpinBeans[0].s_id"></td> <td>商品名称:<input type="text" name="name"></td> <td>商品单位:<input type="text" name="dan"></td> <td>商品简介:<input type="text" name="xiangxi"></td> <td>随便填一个数字:<input type="text" name="c_id"></td> <td>状态:<input type="text" name="statu"></td> </tr> </table>获取到input中的name
时间: 2023-07-19 16:15:53 浏览: 100
可以通过以下方式获取到input中的name:
```javascript
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
console.log(inputs[i].name);
}
```
这段代码会获取到文档中所有input元素,并输出它们的name属性值。在这个例子中,输出会是:
```
shangpinBeans[0].s_id
name
dan
xiangxi
c_id
statu
```
相关问题
html <table border bgcolor="#eeeeee"> <tr><td(l)align=center><b>情况登记</b><tr><td>姓名:<td>(2) <tr><td>密码:<td><INPUT size="20" _(3) value="pwd"> <tr><td> 性别:<td><INPUT name="sex" type=radio> 男<INPUT name="sex" type=radio>女 <tr><td> <td><INPUT (4)_value=”提 交“><INPUT type="reset"(5)></table></form>
```html
<form>
<table border bgcolor="#eeeeee">
<tr>
<td align=center><b>情况登记</b></td>
</tr>
<tr>
<td>姓名:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>密码:</td>
<td><input size="20" type="password" name="password" value="pwd"></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="radio" name="sex" value="male">男 <input type="radio" name="sex" value="female">女</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交"><input type="reset" value="重置"></td>
</tr>
</table>
</form>
```
<table> <tr><td>pid:</td><td><input type="text" name="pid"> </td></tr> <tr><td>pname:</td><td><input type="text" name="pname"> </td></tr> <tr><td>shop_price:</td><td><input type="text" name="shop_price"> </td></tr> <tr><td>cname:</td><td><input type="text" name="cname"> </td></tr> <tr><td>pimage:</td><td><input type="file" name="pimage"> </td></tr> <tr><td colspan="2"><input type="submit" value="添加商品"></td></tr> </table>通过前端输入这些数据,点击添加商品后将输入的数据插入数据库的products表里,同时回到showAllPoducts.jsp页面展示输入的商品信息的数据,商品pid不能重复输入,它是products表的主键的代码
下面是一个示例代码,实现了前端输入数据并插入数据库表的操作,同时也实现了商品pid不能重复输入的限制,并且回到 showAllProducts.jsp 页面展示输入的商品信息数据。
```
<%
String pid = request.getParameter("pid");
String pname = request.getParameter("pname");
String shop_price = request.getParameter("shop_price");
String cname = request.getParameter("cname");
String pimage = request.getParameter("pimage");
// 检查pid是否已存在
boolean pidExists = false;
try {
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM products WHERE pid = ?");
pstmt.setString(1, pid);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
pidExists = true;
}
rs.close();
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
// 如果pid已存在,则返回错误信息
if (pidExists) {
out.print("Error: pid already exists");
} else {
// 如果pid不存在,则插入数据到数据库表中
try {
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO products (pid, pname, shop_price, cname, pimage) VALUES (?, ?, ?, ?, ?)");
pstmt.setString(1, pid);
pstmt.setString(2, pname);
pstmt.setString(3, shop_price);
pstmt.setString(4, cname);
pstmt.setString(5, pimage);
pstmt.executeUpdate();
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
// 返回 showAllProducts.jsp 页面,并展示输入的商品信息的数据
response.sendRedirect("showAllProducts.jsp");
}
%>
```
请注意,上述代码并不完整,需要根据具体的项目需求进行适当的修改和调整。同时,为了确保数据安全,需要对用户输入的数据进行校验和过滤,以防止 SQL 注入等安全问题。
阅读全文
相关推荐




<form action="select.jsp" method="post"> id:<input type="text" name="sid"> <input type="submit" value="查找"> </form> <form action="xiugai.jsp" method="post"> <form action="detele.jsp" method="post"> id <input type="text" name="id" value="<%=request.getParameter("id")==null?"":request.getParameter("id")%>"/> name <input type="text" name="name" value="<%=request.getParameter("name")==null?"":request.getParameter("name")%>"/> cid <input type="text" name="cid" value="<%=request.getParameter("cid")==null?"":request.getParameter("cid")%>"/> cname <input type="text" name="cname" value="<%=request.getParameter("cname")==null?"":request.getParameter("cname")%>"/> <input type="submit" value="修改"> <input type="submit" value="删除"> 添加 </form> </form> 对该代码进行页面美化




<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> 新用户注册 USER REGISTER <form action="#" method="post"> <label for="username">用户名</label> <input type="text" name="username" id="username" placeholder="请输入用户名"> <label for="birthday">出生日期</label> <input type="date" name="birthday" id="birthday" placeholder="请输入出生日期"> <label for="checkcode" >验证码</label> <input type="text" name="checkcode" id="checkcode" placeholder="请输入验证码">
<input type="submit" id="btn_sub" value="注册"> </form> 已有账号?立即登录 </body> </html> </body> </html>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>添加合同信息</title> </head> <body bgcolor = "lightgreen"> <form action="http://localhost:8080/EIMS/contactManage/addContactCheck.jsp" method = "post"> 合同查询 合同添加
添加合同信息 客户姓名 <input type = "text" name = "clientName"/> 合同名称 <input type = "text" name = "contactName"/> 合同内容 <input type = "text" name = "contactContents"/> 合同有效日期 <input type = "text" name = "contactStart"/> 合同有效期 <input type = "text" name = "contactEnd"/> 业务员姓名 <input type = "text" name = "StaffName"/> <input type = "submit" name = "sure" value = "确认"/> <input type = "reset" name = "clear" value = "取消"/> </form> </body> </html>



<body> 教师登录 <form name="loginfrm" action="TServlet" method="post" class="margin"> 用户名: <input type="text" name="username" class="textrange" class="textrange"> 密 码: <input type="password" name="password1" class="textrange"> 验证码:
<input type="text" class="inputgri" name="checkCode" id="code" onblur="checkInputCode();"/>
<input name="button" type="submit" value="登录" onclick="">
没有账户,点击注册 </form> 让它变得炫酷

<body> <form action="QueryServlet" method="post"> 请输入用户名:<input type="text" name="userName"/> <input type="submit" value="查询"/> 显示全部 </form> 用户名 密码 积分 注册时间 <c:forEach items="${users }" var="item"> ${item.userName } ${item.password } ${item.integral } ${item.registerTime } 删除 </c:forEach> </body>tomcat 删除一条记录怎么写

把一下代码生成流程图 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>register</title> <script src="js/zone.js"></script> </head> <body> 注册 用户名: <input type="text" id="username" autocomplete="off" placeholder="输入姓名"> 密码 <input type="password" id="password" placeholder="输入密码"> 确认密码 <input type="password" id="repwd" placeholder="确认密码"> <input type="button" value="注册" id="register" onclick="reg()"> 登录 </body> </html>


