实现简单的二级级联

1、源码

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <title></title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="../../js/jquery-1.11.1.js"></script>
	<style type="text/css">
	    .body_tag{
	        width: 100%;
	        height: 100%;
	    }
	</style>
    <script type="text/javascript">
        /**
         *
         */
         function province()
         {
             var proName = $("#areaName").val();
             $("#city").empty();
             $("#city").append("<option value=‘0‘>全部</option>");
             if(proName == "1")
             {
                 $("#city").append("<option value=‘1‘>广州市</option>"+
                 				   "<option value=‘2‘>深圳市</option>"+
                 				   "<option value=‘3‘>中山市</option>");
             }
             if(proName == "2")
             {
                 $("#city").append("<option value=‘1‘>武汉市</option>"+
                 				   "<option value=‘2‘>黄石市</option>"+
                 				   "<option value=‘3‘>黄冈市</option>");
             }
         }
    </script>
  </head>

  <body class="body_tag">
     <table id="tab">
         <tr>
           <td>
             <label for="areaName">省份:</label>
             <select id="areaName" onchange="province()">
                  <option value="0">全国</option>
                  <option value="1">广东</option>
                  <option value="2">湖北</option>
             </select>
             <label for="city">地市:</label>
             <select id="city">
                  <option value="0">全部</option>
             </select>
           </td>
         </tr>
     </table>
  </body>
</html>

2、结果

(1)初始化

(2)选择广东

(3)选择湖北

实现简单的二级级联

时间: 2024-12-04 22:55:42

实现简单的二级级联的相关文章

jsp+js实现二级级联

本文实现学院-专业二级级联,同理可用到省份-城市,洲-国家等级联,即通过不同的首选择,自动找到属于第一选择的二次可选项. test.jsp <%@ page language="java" contentType="text/html; charset=gb2312" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.ge

利用JS实现一个简单的二级联动菜单

前几天在看js的相关内容,所以就简单写了一个二级联动菜单.分享一下. 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>JS实现二级联动菜单</title> 6 </head> 7 <body> 8 <form name="form1"

jQuery+Ajax+Jsp做二级级联

终于弄懂了这个级联,我去!必须得在博客记下来. 1, JS代码: 1 $(document).ready(function(){ 2 $("#select1").change(function(){ 3 adjustCountyDropDown(); 4 }); 5 }); 6 7 function adjustCountyDropDown(){ 8 var selectedCity= $("#select1").val(); 9 var county= $(&qu

简单得二级联动

<!--/*--><!--* Created by sincere丶胡(weibo) on 2017/6/28.--><!--*/--><!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>yadi</title> <meta name="viewport&quo

一个简单的二级联动效果,看完之后立马你也可以写一个(有源码,纯js,带注释)

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>选择</title> <meta name="viewport" content="initial-scale=1.0, width=device-width,minimum-scale=1.0,maximum-scale=1

通同select便签实现简单的二级联动

<!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-

jq实现简单的二级联动下拉框

1 效果图 2 html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compati

Js实现简单的省市级联的效果

需要注意的是当需要动态添加项的时候一定要先var newoption=new Option("项","值");然后再 select.options.add(newoption);这样才能添加进去代码如下: <html> <head> <script language="javascript"> function changeSever() { var newop1,newop2; //声明两个变量用来添加Opt

php简单实现二级联动

<script type="text/javascript"> //当第一级选项发生变化的时候跳转 function jump() { location.href='?firstid='+document.getElementById('first').value; } </script> <?php //连接数据库 @mysql_connect('localhost','root',''); mysql_select_db('test'); mysql_