以下是用于简单html的代码,它可以工作:
<select id="name" class="state">
<option value="Brad" selected="selected">
Brad
</option>
<option value="Carol">
Carol
</option>
<option value="Derrick">
Derrick
</option>
</select>
我可以使用其他方法,以便可以为我的select选项标签设置默认值吗?
在我的jsp文件中:
</html:select>
<html:option value="0">--Select--</html:option>
<html:option value="Brad" selected="selected">Brad</html:option>
<html:option value="Carol">Carol</html:option>
</html:select>
<option value="Brad" selected="selected"> Brad </option>
适用于简单的html。在单击下拉箭头之前显示Brad。我的问题是,当我在我的jsp中使用它时,它表示&#34;该属性无法识别<html:option value="Brad" selected="selected">Brad</html:option>
&#34;
答案 0 :(得分:0)
如果您使用的是JSP
,那么tag
就会有html-select-dropdown
。使用<form:select>
标记,您可以执行以下操作 -
<form:select path="country">
<form:option value="NONE" label="--- Select ---"/>
<form:options items="${yourList}" />
</form:select>
要详细了解如何使用 jsp select tag 深入了解此link。
对于分配默认值,请从answer获取帮助。
<强>更新强>
您可以在JSTL
JSP
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
在这里,您可以看到prefix="form"
,您可以根据需要为prefix
命名。您可以找到更多详细信息here。
答案 1 :(得分:0)
=“选定”部分不是必需的。只需<option selected>
即可。
<select id="name" class="state">
<option selected value="Brad">
Brad
</option>
<option value="Carol">
Carol
</option>
<option value="Derrick">
Derrick
</option>
</select>
除非选择了其他选项,否则该值(在本例中为“Brad”)将作为字符串传递。