简体   繁体   English

禁用先前选择的下拉选项,同时检查文本和ID值

[英]disable previously selected dropdown option, check both text & id value

In a table, how to loop through all dropdowns text & id in a table's col, and save them in array. 在表格中, 如何遍历表格列中的所有dropdowns textid ,并将其保存在数组中。 So that I can disable previously selected options 这样我就可以禁用以前选择的选项

Once an option is selected, I do not want it to be available again . 选择一个选项后,我不希望它再次可用 How to check the selected text of previously selected options in the table set that option to disabled on all other dropdowns in the page. 如何检查表中先前选择的选项 的选定文本 ,将该选项在页面上的所有其他下拉列表中设置为禁用。

(this question is different from other SO questions since its disabling after checking both selected text & selected value inside a table and needs to target the dropdown in the specified column) (此问题与其他SO问题不同,因为它在检查了表中的selected textselected value之后将其禁用,并且需要将指定列中的下拉列表作为目标)

var allSelectedValuesArray = array();
allSelectedValuesArray.push($("#tblVersions .Model option:selected").text());

var rows = $("body tr",$("#tblVersions")).map(function() { 
return [$("td:eq(0) input:checkbox:checked",this).map(function() { 
  return this.innerHTML;     
}).get()];
}).get();

<table id="tblversions">
 <tbody id="body">
  <tr class="rowcss">
   <td>
    <select class="Manufacturer">
      <option value="1">Toyota </option>
      <option value="2">Honda</option>
      <option value="3">BMW</option>
    </select>
   </td>
   <td>
   <select class="Model"> 
   <!-- If user selects Honda my Ajax populates Honda Models/Cars like below-->
      <option value="1">Accord</option>
      <option value="2">Toyota 2</option>
      <option value="3">Honda 3</option>        
    </select>
   </td>
   </tr>
    <tr class="rowcss">
    <td>
    <select class="Manufacturer">
      <option value="1">Toyota </option>
      <option value="2">Honda</option>
      <option value="3">BMW</option>
    </select>
    </td>
    <td>
    <select class="Model">
    <!-- If user selects BMW my Ajax populates BMW models Cars like below-->
      <option value="1">X5 Suv</option>
      <option value="2">318 series Cheap</option>
      <option value="3">540i too expensive!</option>        
    </select>
   </td>
  </tr>     
 </tbody>
 </table>

I didn't understand the second part of your question, but if you want to get text and values for all dropdowns you could do something like this. 我不理解您问题的第二部分,但是如果您想获取所有下拉菜单的文本和值,则可以执行以下操作。

// Called when any of the dropdowns change
( "#tblversions" ).change(function() {
    var allSelectedValuesArray = [];

    // Search for all selects in the #tblversions
    $("#tblversions select option:selected").each(function() {
        // for each one, push it into the array
        allSelectedValuesArray.push({text:$(this).text(), value:this.value});
    });
});

This creates an array of objects in the format {text:"sometext",value:"somevalue"} for each of the dropdowns in the table. 这会为表中的每个下拉列表以{text:“ sometext”,value:“ somevalue”}格式创建对象数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM