1、省市县的数据写到数据库中。每条数据会有一个父ID(上级ID)。
2、在页面上省变动后,查询市的数据以省的ID作为条件,县也一样,以市 的ID为条件。
第二种方法,
由于全国的这些基本上是固定的,一般变动比较少,这可以把这个数据写到JS里面,通过JS来实现。这个加载会快一些。这些数据可以到国家统计局的网站去下载。
<!DOCTYPE html><html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
$("#add").click(function(){
var sum = $("#sum").val()
var result = Number(sum)+1
$("#sum").val(result)
})
$("#down").click(function(){
var sum = $("#sum").val()
var result = Number(sum)-1
$("#sum").val(result)
})
})
</script>
</head>
<body>
<input id='sum' value='0'>
<p id='add'>添加</p>
<p id='down'>减少</p>
</body>
</html>
跟这个类似
淘宝是我们经常用的一个网上购物平台,打开淘宝网首页,找到淘宝首页的搜索框,如下如所示:大家可以看到,当页面一打开,搜索框中就可以看到灰色字体“少女高跟鞋”,还有闪烁的光标。当用户点击输入的时候,灰色字消失。当用户清空文本框的所有内容的时候,灰色字自动恢复。
接下来,这个小案例就是要介绍如何实现这种效果,即用户输入事件。
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>判断用户输入事件第2遍oninput 和onpropertychange 的用法</title></head><style>.search { width:300pxheight: 30pxmargin: 100px autoposition: relative} .search input { width:200pxheight:25px} .search label { font-size: 12pxcolor:#cccposition: absolutetop:8pxleft:10pxcursor: text} </style><script type="text/javascript">业务逻辑分析: // 1.内容为空时,光标和默认字显示在搜索框。自动获取焦点 // 2.当输入内容时,默认字消失。用oninput事件 window.onload = function () { function $(id){ return document.getElementById(id)} $("txt").focus()//自动获取光标方法 $("txt").oninput = $("txt").onpropertychange = function () { //oninput 大部分浏览器支持 检测用户表单输入内容 //onpropertychange ie678 检测用户表单输入内容 if ( this.value == ""){ // 首先判断文本框里的值是否为空。注意用双等号! $("message").style.display = "block"} else { $("message").style.display = "none"