【问题标题】:Jquery get the list itemjquery获取列表项
【发布时间】:2011-12-07 03:57:49
【问题描述】:

如何获取第二个列表项的值并分配给文本框。例如,我的第二个列表项是“编辑配置文件”,然后在 textbox1 文本更改之后,文本框 2 将自动分配“编辑配置文件” 这是我的编码

   <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;
}

【问题讨论】:

    标签: c# jquery asp.net listitem


    【解决方案1】:

    仅按索引引用:

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

    Arraylist and webmethod

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 2011-07-29
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 2016-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多