<td><input class="text w8" name="spId" maxlength="64" required></td> input不给编辑怎么写
时间: 2023-07-19 19:40:07 浏览: 57
如果您想让用户无法编辑输入框,可以将其设置为只读(readonly)或禁用(disabled)状态。只读状态允许用户查看但不能编辑输入框内容,而禁用状态则将输入框变为灰色且无法被选中。
以下是两个示例:
只读输入框:
```
<input class="text w8" name="spId" maxlength="64" required readonly>
```
禁用输入框:
```
<input class="text w8" name="spId" maxlength="64" required disabled>
```
请注意,禁用状态的输入框不会被提交到服务器,因此如果您需要将其值提交,请使用只读状态的输入框。
相关问题
while (rs.next()) { application.setAttribute("id", rs.getString("spid")); application.setAttribute("goods_name", rs.getString("itemname")); application.setAttribute("goodspic", rs.getString("price")); //application.setAttribute("blob", rs.getString("blob")); %> <tr> <td width = "100px" height = "42px"> <input name="one" type="checkbox" onclick="myOne()"/> </label> </td> <td width = "135px" height = "42px"><%=application.getAttribute("id") %></td> <td width = "150px" height = "42px"><%=application.getAttribute("goods_name")%></td> <td width = "150px" height = "42px" id="price"> <img src="yuan.jpg" width="20" heigth="20"> <%=application.getAttribute("goodspic")%> </td> <td width = "240px" height = "42px" id="car"> <input type="button" class="decrease" value="-"> <input type="text" class="quantity" value="1"/> <input type="button" class="increase" value="+"> </td> <td width = "135px" height = "42px"> <input type="button" class="deldet" value="删除此商品"> </td> </tr> <% } %>根据以上代码编写购物车价格总计并当页显示
可以在代码中加入以下部分来实现购物车价格总计并当页显示:
```
<%
double total = 0;
ResultSet rs = ... // 数据库查询代码
while (rs.next()) {
// ... 数据库查询结果处理代码
double price = Double.parseDouble((String)application.getAttribute("goodspic"));
total += price;
// ... HTML代码
}
%>
<tr>
<td colspan="3"></td>
<td>总计:</td>
<td colspan="2"><%= total %></td>
</tr>
```
其中,`total` 变量用来存储购物车中所有商品的价格总和,`price` 变量用来存储当前商品的价格,`Double.parseDouble()` 方法用来将字符串类型的价格转换为浮点数类型。在 HTML 代码中,使用 `<td>` 元素来显示总计价格。这里使用了 `colspan` 属性来让总计这一行占据两列,以便居中显示。
try{ request.setCharacterEncoding("utf-8"); //加载驱动程序 Class.forName("com.mysql.cj.jdbc.Driver");//8.0 //建立连接 Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/petstore?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai","root","root"); //8.0 session.getAttribute("userid"); Statement stmt=conn.createStatement(); // 结果集 ResultSet rs = stmt.executeQuery("select * from `scar`"); //ResultSet rs = stmt.executeQuery("select * from `scar` where uid="+session.getAttribute("userid")+""); while (rs.next()) { application.setAttribute("id", rs.getString("spid")); application.setAttribute("goods_name", rs.getString("itemname")); application.setAttribute("goodspic", rs.getString("price")); //application.setAttribute("blob", rs.getString("blob")); %> <tr> <td width = "100px" height = "42px"> <input name="one" type="checkbox" onclick="myOne()"/> </label> </td> <td width = "135px" height = "42px"><%=application.getAttribute("id") %></td> <td width = "150px" height = "42px"><%=application.getAttribute("goods_name")%></td> <td width = "150px" height = "42px" id="price"> <img src="yuan.jpg" width="20" heigth="20"> <%=application.getAttribute("goodspic")%> </td> <td width = "240px" height = "42px" id="car"> <input type="button" class="decrease" value="-"> <input type="text" class="quantity" value="1"/> <input type="button" class="increase" value="+"> </td> <td width = "135px" height = "42px"> <input type="button" class="deldet" value="删除此商品"> </td> </tr> <% } %>此代码条件下写商品数量的按钮加减,商品小计与商品总价并当页显示
这段代码中缺少一些关键信息,比如商品数量的初始值、商品价格与数量的关系、商品总价的计算方式等。因此,无法直接给出完整的代码。
但是,你可以参考以下步骤来完成商品数量、小计和总价的显示:
1. 在商品数量的输入框中设置初始值,例如:
`<input type="text" class="quantity" value="1"/>`
2. 使用 JavaScript 监听商品数量的输入框的值的变化,例如:
```
$('.quantity').on('input', function() {
// TODO: 更新商品小计和总价
});
```
3. 根据商品数量和价格计算出商品小计,例如:
```
var quantity = parseInt($(this).val()); // 获取商品数量
var price = parseFloat($('#price').text()); // 获取商品价格
var subtotal = quantity * price; // 计算商品小计
$('#subtotal').text(subtotal.toFixed(2)); // 显示商品小计,保留2位小数
```
4. 根据所有商品的小计计算出商品总价,例如:
```
var total = 0;
$('.subtotal').each(function() {
total += parseFloat($(this).text());
});
$('#total').text(total.toFixed(2));
```
其中,`#subtotal` 和 `#total` 分别是显示商品小计和总价的元素的 ID。注意,`toFixed()` 方法可以将小数保留指定的位数。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](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)