使用Ajax从下拉列表转换为输入文本框

时间:2014-12-07 06:18:50

标签: php jquery ajax

对不起标题。

如何将此代码从下拉列表修改为输入文本框,以便不是填充下拉列表,而是从getCustomer.php代码填充输入文本框?

function getOrgCodes() {
    $.ajax({
        url: 'getCustomer.php',
        dataType: 'json'
    })
    .done(function(orgInfo) {
        $(orgInfo).each(function(i, orgdisplay) {
            $('<option>').val(orgdisplay.ORGANIZATION).text(orgdisplay.ORGANIZATION).appendTo( $('#deptId') );
        })
    });
}

1 个答案:

答案 0 :(得分:0)

<option>替换为<input type="text">

function getOrgCodes() {
    $.ajax({
        url: 'getCustomer.php',
        dataType: 'json'
    })
    .done(function(orgInfo) {
        $(orgInfo).each(function(i, orgdisplay) {
            $('<input type="text">').val(orgdisplay.ORGANIZATION).appendTo( $('#deptId') );
        })
    });
}

替换后你不需要.text(orgdisplay.ORGANIZATION).val(orgdisplay.ORGANIZATION)会在文本框中设置值。

请参阅此迷你演示:http://jsfiddle.net/rdesai/hfczjzhy/

相关问题