简体   繁体   English

如何从其他下拉列表中删除在上一个下拉列表中选择的选项

[英]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}(&#8364;${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}(&#8364; ${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}(&#8364; ${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.

相关问题 从 Angular 的下拉列表中删除选定的选项 - Remove selected option from drop down in Angular 根据从其他组合框中选择的选项更改下拉选项 - Change the drop down option based on the selected option from other combobox angularjs根据其他下拉列表中的选定值过滤下拉列表 - angularjs filter drop-down list according to selected values in other drop-down lists 从下拉可用选项中删除选定的选项 - remove selected option from drop-down available options 删除其他下拉列表中的选定条目 - Remove selected entry on other drop-down list 从未来的下拉选项中删除先前的下拉选项 - Remove previous drop down selection from future drop down options 如何使用取决于另一个下拉列表中所选选项的下拉列表显示表格简码 - how to display table shortcode with a drop-down list that depends on the selected option in another drop-down list 使用javascript在下拉列表中显示选定的选项 - Display a selected option from a drop down list into a box using javascript 从下拉列表中删除所有选项,然后使用javascript在下拉列表中设置一个值 - remove all the option from drop down list and then set a value in drop down list using javascript 如何在选择下拉列表的选项中设置所选属性 - how to set selected attribute in option for select drop down list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM