码迷,mamicode.com
首页 > Web开发 > 详细

jquery或者js对html控件的处理汇总

时间:2015-08-25 21:01:43      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

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

 

jquery或者js对html控件的处理汇总

标签:

原文地址:http://www.cnblogs.com/yonguibe/p/4758308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!