1.能自动带出地址,区号,邮政编码
2.省市区三级联动xml/json
3.附带省市区,区号,邮政编码的MySQL
bug bind失效
- $("#"+currentSelect.id).unbind("change");
- $("#"+currentSelect.id).live("change", function(){
city.php
- <?php
- $connect = mysql_connect(HOST, USER, PW)or die('Could not connect to mysql server');
- mysql_select_db(DB, $connect) or die('Could not select database.');
- //设置查询编码,不设查询时易出现乱码
- mysql_query('set names utf8;');
- $sql = "select cityid,city from `cities` where provinceid=" . $_POST['parentId'];
- $result = mysql_query($sql) or die (mysql_error());
- $list = array();
- if (mysql_num_rows($result) > 0) {
- while ($row = mysql_fetch_array($result)) {
- $list[] = array('value' => $row['cityid'], 'label' => $row['city']);
- }
- }
- //print_r($list);
- echo JSON($list);
- mysql_free_result($result);
html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="LinkedSelect.js"></script>
- <script type="text/javascript" charset="utf-8">
- var select = new LinkedSelect();
- // 调用selct的init()方法,注意,该方法的参数是一个数组,用[]括起来,每个select的定义用{}括起来,多个select定义之间以,分割
- select.init([
- {
- id:"province",
- url:"http://localhost/provinces.php",
- nullable:false,
- defaultValue:'230000' //selected
- },
- {
- id:"city",
- url:"http://localhost/city.php",
- nullable:false
- }
- ]);
- </script>
- <select name="province" id="province">
- </select>
- <select name="city" id="city">
- </select>
- </html>