从选择框中获取选定的值,并以相同的形式对照数组检查该值
我是 JSTL/EL 和 JSP 的新手,似乎找不到涵盖以下场景的参考:
我在 JavaScipt 中有一个值数组:
var Countries = ('US', 'CA');
然后我需要检查当前选择的标准 HTML 值是否为select
框位于该数组中。
这是我到目前为止所拥有的:
<select id="shippingCountry">
<option value="AT">Austria</option>
<option value="CA">Canada</option>
<option value="DE">Germany</option>
//...
<option value="US">United States</option>
</select>
<c:choose>
<c:when test=" "> // I don't know what to put in the 'test' case
<span class="required">*</span>
</c:when>
</c:choose>
I'm new to JSTL/EL and JSP and can't seem to find a reference which covers the following scenario:
I have an array of values in JavaScipt:
var Countries = ('US', 'CA');
I then need to check to see if the currently selected value of a standard HTML select
box is in that array.
This is what I have so far:
<select id="shippingCountry">
<option value="AT">Austria</option>
<option value="CA">Canada</option>
<option value="DE">Germany</option>
//...
<option value="US">United States</option>
</select>
<c:choose>
<c:when test=" "> // I don't know what to put in the 'test' case
<span class="required">*</span>
</c:when>
</c:choose>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您已经在 Javascript 数组中拥有了值,因此使用 Javascript 测试该值可能更有意义。否则,您将发生回发,并且工作量可能会显着增加。
Since you already have the values in a Javascript array, it probably makes more sense to test for that value using Javascript. Otherwise, you'd incur a postback and it would probably be significantly more work.