2012-05-14 65 views

回答

0

您必须通过AJAX调用获得选项,然后使用DOM为请求回调中的下拉菜单添加一个选项。

0

为了促进这项工作,我建议使用jQuery库: http://jquery.com/

查找Ajax的功能: http://api.jquery.com/jQuery.ajax/

所以,你将有2页,

的index.php:

<html> 
    <head> 
    </head> 
    <body> 
     <select id="dropdown"> 
      <option value="default" selected="selected">Default option</option> 
     </select> 
     <script type="text/javascript"> 
      $.ajax({ 
       url: 'dropdown-choices.php', 
       success: function(data) { 
       $('#dropdown').append(data); 
       } 
      });     
     </script> 
    </body> 
</html> 

dropdown-choices.php:

<?php 
    $sql = mysql_query("SELECT * FROM dropdown_choices;"); 
    while ($data = mysql_fetch_assoc($sql)) { 
     echo '<option value="'+$data['value']+'">'+$data['name']+'</option>'; 
    } 
?> 

这应该这样做:)

相关问题