且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

阻止每个表行的多个相同值选择

更新时间:2023-02-06 11:04:43

我在代码中使用相同的代码你提供的链接,但它与表格行相关:

I use the same code in the link you provided but it's contexted to the table row :

$("select").change(function()
 {
     var tr = $(this).closest("tr");
        tr.find("select option").attr("disabled",""); //enable everything

     //collect the values from selected;
     var  arr = $.map
     (
        tr.find("select option:selected"), function(n)
         {
              return n.value;
          }
      );

    //disable elements
    tr.find("select option").filter(function()
    {

        return $.inArray($(this).val(),arr)>-1; //if value is in the array of selected values
     }).attr("disabled","disabled");   

});