简体   繁体   English

如何使用Jquery选择特定的列表框项目?

[英]How to select the particular list box item using Jquery?

I want to select one of the list box item when user select the table row. 当用户选择表格行时,我想选择一个列表框项目。

这是我的输出aspx.page

The last item user added SupplierCode to a table by clicking ADD Button . 最后一位用户通过单击ADD ButtonSupplierCode添加到表中。 When user want to modify the records from table, once they click that particular row, the value should move to FilterValue and Field in the list box should select that particular Field Name which is selected by user. 当用户想要从表中修改记录时,一旦他们单击该特定行,该值应移至FilterValue,并且列表框中的字段应选择该特定字段名,该字段名由用户选择。

Now user select the first row to modify the value. 现在,用户选择第一行以修改值。 That value is moved to FilterValue textbox , But list box item is not selected automatically to StoreID 该值将移动到FilterValue textbox ,但是列表框项目不会自动选择为StoreID

看到这张照片

But when I check the code in browser. 但是当我在浏览器中检查代码时。 it shows selected for that particular item which item user wants to select, but the color is not changed. 它显示为该特定项目选择的项目,用户希望选择该项目,但颜色不会更改。

This is my code 这是我的代码

Jquery code jQuery代码

    //SELECT Table ROW
$(document).on("click", '#queryTable tbody tr', function () {
    var tr = $(this);
    var FieldName = tr.find("td:first").text();
    var Values = tr.find("td:last").text();

    FieldName = FieldName.replace('AND ', '');
    FieldName = FieldName.replace('OR ', '');

    Values = Values.replace('IN(', '');
    Values = Values.replace(')', '');
    alert(FieldName + ' ' + Values);

    $("#FilterField option[value=" + FieldName + "]").attr("selected", true);
    $("#txtFilterValue").val(Values);
});

try with following code and check if it works 尝试下面的代码,并检查是否有效

 //SELECT Table ROW
$(document).on("click", '#queryTable tbody tr', function () {
    var tr = $(this);
    var FieldName = tr.find("td:first").text();
    var Values = tr.find("td:last").text();

    FieldName = FieldName.replace('AND ', '');
    FieldName = FieldName.replace('OR ', '');

    Values = Values.replace('IN(', '');
    Values = Values.replace(')', '');
    //alert(FieldName + ' ' + Values); provided your FieldName as correct value

    $("#FilterField").val(FieldName);
    $("#txtFilterValue").val(Values);
});

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

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