【问题标题】:converting from dropdown to input textbox using Ajax使用 Ajax 从下拉列表转换为输入文本框
【发布时间】:2014-12-07 06:18:49
【问题描述】:

抱歉标题。

如何将此代码从下拉列表修改为输入文本框,这样输入文本框将由 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') );
        })
    });
}

【问题讨论】:

    标签: php jquery ajax


    【解决方案1】:

    &lt;option&gt; 替换为&lt;input type="text"&gt;

    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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多