EasyUI中combobox 获取选中的id或者text

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq736150416/article/details/78044805

<input type="text" id="ddlCP"  data-options="valueField:'id',textField:'text'" class="easyui-combobox" runat="server"/>

 <input type="hidden" id="hidCp" runat="server"/>  //存id的值
 <input type="hidden" id="hidCpText" runat="server"/> //存text的值 ,方便页面使用


   $('#ddlCP').combobox({
                valueField: 'text',
                textField: 'text',
                onChange: function (values, o) {
                    if (values != "" && (values.length < 5 || (values.length - 1) % 2 == 0)) {
                        if (values.length % 3 == 0) {
                            $('.combo input.combo-text').attr("disabled", true);
                        }
                        var url = '/base/Data/SearchCP.aspx?action=load01&keyword=' + values;
                        $("#ddlCP").combobox("reload", url);
                        $('.combo input.combo-text').removeAttr("disabled");
                    }
                },
                onSelect:function(record){
                    //获取下拉中的数据
                    var data = $('#ddlCP').combobox("getData");
                    console.log(data[0].id+"||"+data[0].text);
                    $("#hidCp").attr("value", data[0].id);
                    $("#hidCpText").attr("value", data[0].text);
                 }
            });

            var comboValue = $("input.combo-value").attr("value");
            if (comboValue == "" || comboValue == null) {
                $("#hidCp,#hidCpText").attr("value", "");
            }
            else {
                $('.combo input.combo-text').attr("value", $("#hidCpText").attr("value"));
            }


             //鼠标离开,设置下拉框中文本框显示的文本

            $('.combo input.combo-text').mouseleave(function () {
                var comboValue=$("input.combo-value").attr("value");
                if (comboValue == "" || comboValue == null) {
                    $("#hidCp,#hidCpText").attr("value", "");
                }
                else {
                    $('.combo input.combo-text').attr("value", $("#hidCpText").attr("value"));
                }
            });







展开阅读全文

没有更多推荐了,返回首页