duanche2007 2014-12-06 22:18
浏览 59
已采纳

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

Sorry for the title.

How do I modify this code from dropdown to input textbox in such that instead of populating dropdown, input textbox will be populated from getCustomer.php code?

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条回答 默认 最新

  • douyun3799 2014-12-06 22:42
    关注

    Replace <option> with <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') );
            })
        });
    }
    

    You dont need that .text(orgdisplay.ORGANIZATION) after you do the replacement. .val(orgdisplay.ORGANIZATION) will set the value inside the textbox.

    See this mini-demo: http://jsfiddle.net/rdesai/hfczjzhy/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部