因为我这个是修改功能,所以在把<option>
循环展示出来还不够,还得把当前需要修改的字段默认显示
由于水平有限,试了一两天了都没成功,每天大概两个小时吧。
最后终于用<c:choose><c:when><c:otherwise>
实现了!
成功那一刻真的很开心啊。那种喜悦,确实赞!
我想这就是作为程序员的动力之一吧!
贴上成功后的代码片段:
(ps.DN勿喷)
<select name="goods_type" id="goods_type">
<!-- <c:if test="${bean eq pd.goods_type }">selected</c:if> -->
<c:forEach items="${list}" var="bean">
<c:choose>
<c:when test="${pd.goods_type eq bean}">
<option value="${bean}" selected>
${bean}
</option>
</c:when>
<c:otherwise>
<option value="${bean}">
${bean}
</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
—-update
趁我还记得,先把select标签可写 贴出来
<select name="select" id="sid" style="position:absolute;left:10px;top:10px;width:100px;height:18px;" onchange="textArea.value = select.value;textArea.select()">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="text" name="textArea" style="position:absolute;left:10px;top:10px;width:80px;height:14px;">
好了,大致是这么写的,个别样式可以小调下。
原理应该就是用<input>
把<select>
的地方给代替掉了
最关键的一个地方就是 textarea.value = select.value;
textarea.select()
select()是jquery的一个方法
用于在文本域后添加文本,以显示出提示文本
当 textarea 或文本类型的 input 元素中的文本被选择时,会发生 select 事件。
上面两句是w3c的解释,我觉得好麻烦,一下子理解不了
反正我就理解成此时的select中的值已变成input的值了
所以点击该值就相当于input值被选中了
选中之后触发了select()事件,就在文本域后添加了该值