实用小例:
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 中 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;
- ?>
来源: http://www.bubuko.com/infodetail-3360850.html