0

我的链式选择框目前工作正常。第一个选择框是车辆品牌或vmake,第二个框是车辆型号或vmodel。现在,只有在页面加载时才会出现 vmake 选择框,并且只有在您为 vmake 选择了值后才会出现 vmodel 框。我的客户希望在页面加载时出现 vmodel 和 vmake 选择框(即使在用户从 vmake 进行选择之前 vmodel 框是空的)。这听起来很傻,但客户真的想要这样。

这是来自主页的jquery代码

 <script type="text/javascript">$(document).ready(function() {
    $('#wait_1').hide();
    $('#vmake').change(function(){
      $('#wait_1').show();
      $('#result_1').hide();
      $.get("func.php", {
        func: "vmake",
        drop_var: $('#vmake').val()
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
        return false;
    });
});
function finishAjax(id, response) {  $('#wait_1').hide(); $('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>

这是调用 php 页面的 HTML

<select name="vmake" id="vmake">

  <option value="" selected="selected">Make</option>

  <?php getTierOne(); ?>

</select> 

<span id="wait_0">
</span>
<span id="result_1"></span>

这是调用我的数据库的 getTierOne 的 php 脚本

function getTierOne(){$result = mysql_query("SELECT DISTINCT vmake FROM vmake") 
or die(mysql_error());

  while($tier = mysql_fetch_array( $result )) 

    {
       echo '<option value="'.$tier['vmake'].'">'.$tier['vmake'].'</option>';
    }}

最后这是 php 的其余部分

 if($_GET['func'] == "vmake" && isset($_GET['func']))
 {vmake($_GET['drop_var']); 
}
function vmake($drop_var)
{  
include_once('db.php');
    $result = mysql_query("SELECT * FROM vmake WHERE vmake='$drop_var'") 
    or die(mysql_error());

    echo '<select name="vmodel" id="vmodel" style="width:242">
          <option style="width:242" value=" " selected="selected">Model</option>';

           while($drop_2 = mysql_fetch_array( $result )) 
            {
              echo '<option style="width:242" value="'.$drop_2['vmodel'].'">'.$drop_2['vmodel'].'</option>';
            }

    echo '</select> ';}

我不确定我需要更改什么才能在页面加载时显示 vmodel 框。感谢您的任何建议,对不起,很长的问题。

4

1 回答 1

0
     A dropdown inside another dropdown? Is that posible?

    <select name="vmake" id="vmake">

        <option value="" selected="selected">Make</option>

           <?php getTierOne(); ?> //this function will output   

          "<select name="vmake" id="vmake">
          <option value="" selected="selected">Make</option>
         </select>"

     </select> 
于 2012-06-13T08:44:20.027 回答