zoukankan      html  css  js  c++  java
  • jquery或者js对html控件的处理汇总

    1、下拉列表select的处理

    a)、后台通过jquery获取的json数据对下拉列表select的赋值操作:

    html页面:<select name="gameserverlist" id="gameserverlist"  ></select>

    function JqueryAjaxFun() {
            $.ajax({
                url: "Home/GetGameServerListData",
                type: "get",
                dataType: "json", //表示纯文本
                data: {},
                success: function (data, status) {
                    for (var i = 0; i < data.length; i++) {
                        $("#gameserverlist").append("<option value='" + data[i].server_id + "'>" + data[i].server_name + "</option>");
                    }
                },
                error: function () {//失败
                    alert('Ajax调用失败!');
                }
            });
        }

     js获取当前选中的select值:

           var obj = document.getElementById("gameserverlist"); //定位id
            var index = obj.selectedIndex; // 选中索引
            var text = obj.options[index].text; // 选中文本
            var value = obj.options[index].value; // 选中值
            alert(text + "[" + value + "]");

    jquery获取当前选中的select值:

            var a = $("#gameserverlist  option:selected").text();
            var b = $("#gameserverlist  option:selected").val();
            alert(a + '|' + b);

  • 相关阅读:
    第一次设计作业
    项目选题报告(团队)
    第二次结队作业
    团队第一次作业
    原型设计(结对第一次)
    第二次作业——个人项目实战
    对于软件工程专业的思考
    电场与磁场
    透明层上的层或数字不透明
    Visiual Studio2012 CLR20r3问题
  • 原文地址:https://www.cnblogs.com/yonguibe/p/4758308.html
Copyright © 2011-2022 走看看