[英]How to remove the option which was selected in previous drop down list from other drop down lists
Thanks in advance for any reply. 预先感谢您的任何答复。 I now have a web page from where you can place orders. 我现在有一个网页,您可以在此下订单。 In this web page, you can select a "product A" from a drop down list. 在此网页中,您可以从下拉列表中选择“产品A”。 Once a "product A" is selected, an event is triggered, resulting in another drop down list. 一旦选择了“产品A”,就会触发一个事件,从而导致另一个下拉列表。 Now I want that "product A" will not show in the second drop down list. 现在,我希望“产品A”不会显示在第二个下拉列表中。 Here is the code. 这是代码。
<table style="margin: 0px auto;width: 700px" id="shopTable">
<tr>
<td>
<select name="product" class="product" style="width: 250px" onchange='onchangeprod(this);' >
<c:forEach var="pro" items="${product}">
<option value="${pro.id}" data-price="${pro.price}">${pro.name}(€${pro.price})</option>
</c:forEach>
</select>
</td>
</tr>
The script is as follows. 脚本如下。
function onchangeprod(row){
var test ="<tr>"
+"<td>"
+"<select name='product' class='product' style='width: 250px' onchange='onchangeprod(this);'>"
+"<c:forEach var='pro' items='${product}'>"
+"<option value='${pro.id}' data-price='${pro.price}'>${pro.name}(€ ${pro.price})</option>"
+"</c:forEach>"
+"</select>"
+"</td>"
+"</tr>";
$("#applyTable").append(test);
} <tbody id="applyTable"></tbody>
Supose your previous object id is stored in variable named prevId
then use a if statement in your template to check for that id and print <option>
only for objects with different id 假设先前的对象ID存储在名为prevId
变量中,然后在模板中使用if语句检查该ID,并仅对具有不同ID的对象打印<option>
function onchangeprod(row){
var test ="<tr>"
+"<td>"
+"<select name='product' class='product' style='width: 250px' onchange='onchangeprod(this);'>"
<c:forEach var='pro' items='${product}'>
<c:if test="${pro.id!=prevId}">
+"<option value='${pro.id}' data-price='${pro.price}'>${pro.name}(€ ${pro.price})</option>"
</c:if>
</c:forEach>
+"</select>"
+"</td>"
+"</tr>";
$("#applyTable").append(test);
} <tbody id="applyTable"></tbody>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.