Jquery获取列表项

本文关键字:列表 获取 Jquery | 更新日期: 2023-09-27 18:16:55

如何获得第二个列表项值并分配给文本框。例如,我的第二个列表项是"编辑配置文件",然后在textbox1 textchange之后,textbox2将自动分配"编辑配置文件"这是我的代码

   <script language ="javascript" type="text/javascript">
    $(document).ready(function () {
        $("#TextBox1").bind('change', function (e) {
            if ($("#TextBox1").val() != '') {
                sendData();
            }
        });

        function sendData() {
            var loc = window.location.href;
            loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "t1ViewDB.aspx" : loc;
            $.ajax({
                type: "POST",
                url: loc + "/GetModuleList",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    if (msg.d) {
                        //Get the second list item and assign value to textbox2
                        //???
                        $("#TextBox2").val('');

                    }
                },
                error: function () {
                    alert("An unexpected error has occurred during processing.");
                }
            });
        }
    });

</script>
后端代码

 protected void Page_Load(object sender, EventArgs e)
{
}

[WebMethod()]
public static ArrayList GetModuleList()
{
    ArrayList listArr = new ArrayList();
    listArr.Add(new ListItem("Dashboard"));
    listArr.Add(new ListItem("Edit Profile"));
    listArr.Add(new ListItem("Change Password"));
    return listArr;
}

Jquery获取列表项

仅按索引引用:

 $("#TextBox2").val(msg.d[1]['Value'] );

Arraylist和webmethod