如何在Jquery中的DropDownList中获取空值? [英] How to get a Blank value in DropDownList in Jquery?

查看:98
本文介绍了如何在Jquery中的DropDownList中获取空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Team,



我在 jQuery 中有如下代码。

Hello Team,

I have the code as follows in jQuery.

<select id="batchIDSelect" class="combo100">
    <option>Select </option>
</select>




function GetDisplayBatchID() {
    debugger;
    $.ajax({
        url: 'QCAllocation.aspx/GetDisplayBatchID',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        dataType: "json",
        success: function (result) {
            debugger;
            if (result.d != '') {
                if (result.d != '' && result.d != null) {
                    DisplayBatchIDList = JSON.parse(result.d);
                    var drawRow = function (batchID) {
                        var dropdown = document.getElementById('batchIDSelect');
                        for (var i = 0; i < batchID.length; i++) {
                            var opt = document.createElement('option');
                            opt.innerHTML = batchID[i].BatchId;
                            dropdown.appendChild(opt);
                        }
                    }

                    drawRow(DisplayBatchIDList);
                    manageOverlay(false);
                }
            }

        },
        error: function (error) {
            manageOverlay(false);
            alert(error.responseText);
        },
        async: false
    })
};





我在页面加载时调用 GetDisplayBatchID()。在此,我在 DropDownList 中默认获得选择值。我想在页面加载时保持空白 DropDownList



怎么可能?

我想我们需要修改For循环,你能告诉我如何找到它吗? />
请指导我。



谢谢

Harshal





已更正格式和语法问题。

添加标签。

[/编辑]



I have call GetDisplayBatchID() on page load. In This,I am getting "Select" value by default in DropDownList.I want to keep blank DropDownList when page load.

How it possible?
I think we need to modify the For Loop, will you show me how to find it ?
Please guide Me.

Thanks
Harshal


Corrected formatting and grammatical issues.
Added pre tags.
[/Edit]

推荐答案

.ajax({
url:' QCAllocation.aspx / GetDisplayBatchID'
类型:' POST'
contentType:' application / json; charset = utf-8'
dataType:< span class =code-string> json
成功: function (result){
debugger ;
if (result.d!= ' '){
if (result.d!= ' '&& result.d!= null ){
DisplayBatchIDList = JSON .parse(result.d);
var drawRow = function (batchID){
var dropdown = document .getElementById(' batchIDSelect');
for var i = 0 ; i< batchID.length; i ++){
var opt = document 。 createElement(' option');
opt.innerHTML = batchID [i] .BatchId;
dropdown.appendChild(opt);
}
}

drawRow(DisplayBatchIDList);
manageOverlay( false );
}
}

},
错误:功能(错误){
manageOverlay ( false );
alert(error.responseText);
},
async: false
})
};
.ajax({ url: 'QCAllocation.aspx/GetDisplayBatchID', type: 'POST', contentType: 'application/json; charset=utf-8', dataType: "json", success: function (result) { debugger; if (result.d != '') { if (result.d != '' && result.d != null) { DisplayBatchIDList = JSON.parse(result.d); var drawRow = function (batchID) { var dropdown = document.getElementById('batchIDSelect'); for (var i = 0; i < batchID.length; i++) { var opt = document.createElement('option'); opt.innerHTML = batchID[i].BatchId; dropdown.appendChild(opt); } } drawRow(DisplayBatchIDList); manageOverlay(false); } } }, error: function (error) { manageOverlay(false); alert(error.responseText); }, async: false }) };





我在页面加载时调用 GetDisplayBatchID()。在此,我在 DropDownList 中默认获得选择值。我想在页面加载时保持空白 DropDownList



怎么可能?

我想我们需要修改For循环,你能告诉我如何找到它吗? />
请指导我。



谢谢

Harshal





已更正格式和语法问题。

添加标签。

[/编辑]



I have call GetDisplayBatchID() on page load. In This,I am getting "Select" value by default in DropDownList.I want to keep blank DropDownList when page load.

How it possible?
I think we need to modify the For Loop, will you show me how to find it ?
Please guide Me.

Thanks
Harshal


Corrected formatting and grammatical issues.
Added pre tags.
[/Edit]


尝试如下...

Try like below...
var dropdown = document.getElementById('batchIDSelect');

var opt = document.createElement('option');
opt.innerHTML = ""
dropdown.appendChild(opt);

for (var i = 0; i < batchID.length; i++) {
    var opt = document.createElement('option');
    opt.innerHTML = batchID[i].BatchId;
    dropdown.appendChild(opt);
}


#batchIDSelect option [value ='' ])。attr(' selected' true );
("#batchIDSelect option[value='']").attr('selected', true);



如果有效,请告诉我。


Let me know, if it works or not.


这篇关于如何在Jquery中的DropDownList中获取空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆