【问题标题】:how to avoid duplicate selection of items in dropdown which is in gridview using javascript/jquery如何避免使用javascript / jquery在gridview中的下拉列表中重复选择项目
【发布时间】:2016-08-16 21:35:06
【问题描述】:

我在 gridview(html 中的表格)中有下拉菜单(在 html 中选择)。这个网格视图有多行。我的目标是不允许用户在下拉列表中选择相同的项目。

例如,如果用户选择纽约

分配房间

usernamedropdown        roomnumber
john                       1
john  (this  is wrong)     2

我想处理每个下拉列表的 onchange 并循环遍历网格中的所有值,以及是否有任何下拉值通过错误与所选值匹配。

我尝试了什么

<asp:Gridview id="grdtest" runat="server">

<asp:dropwnlist id="testid"  runat="server" onchange =" checkforvalue(this);">

</asp:Gridview>

JS

function checkforvalue()
{

var valuetocheck= $(testid).selectedvalue;


i am stuck here 

// loop through all rows in gridview\table and find all the value of dropdown and test .


}

【问题讨论】:

    标签: javascript jquery asp.net


    【解决方案1】:

    您可以遍历网格行并定位正确的列/单元格。

    $('#grdtest tr').each(function(i){
       if($(this).find('td').eq(0).text() == valuetocheck){ 
           /* .eq(column index [0 is first]) - I am assuming here
              that your values are stored as strings in the table and 
              using .text() to pluck them out */
           /* duplicate value is present */
       } 
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-01
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多