2014-12-07 30 views
0

對不起,標題。使用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')); 
     }) 
    }); 
} 

回答

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/

+0

非常感謝你 – Tairoc 2014-12-07 07:00:40