php jquery ajax select two way linkage [get]

Practical examples:

ajaxTest.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title> jquery + ajax + php + select  </title>  
</head>  

<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>   


<script language="javascript">  
$(document).ready(function(){  
  $("#bTrade").change(function() {             //jquery 中change()函数  
    $("#quote").load("ajaxTest.? php name = "+ $ ( " # bTrade ") val ());. // jqueryajax the function load ()  
</ Script>
});  
  });  


<select name="bTrade" id="bTrade">  
    <option value="a">a</option>  
    <option value="b">b</option>  
</select>  


<div id="quote">  
 </div>


<body>  
</body>  
</html>  

ajaxTest.php

<?php
    $array = array(
            'a'=>array('a1','a2','a3','a4'),
            'b'=>array('b1','b2','b3','b4'),
        );
    $name=$_GET['name'];

    $str='<select name="server" >';
    foreach($array[$name] as $key=>$value)
    {
        $str.='<option value="'.$key.'">'.$value.'</option>';
    }
    $str.='</select>';
        echo $str; 
?>

Guess you like

Origin www.cnblogs.com/apolloren/p/12129488.html