下拉框的onchange事件和onclick,一般最好都选择onchange事件,onclick可能会不兼容有些浏览器。

下面是代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>选择</title>
<script src="js/lib/jquery/v1.12.3/jquery-1.12.3.js"></script>
<style>
#one {
border: 1px solid salmon;
width: 40px;
height: 100px;
position: absolute;
left: 20px;
}
#two {
border: 1px solid salmon;
width: 40px;
height: 100px;
position: absolute;
left: 61px;
}
#three {
border: 1px solid salmon;
width: 40px;
height: 100px;
position: absolute;
left: 102px;
}
</style>
<script>
function showlist(optvalue){
if(optvalue=="1"){
$( "#select1" ).show();
$( "#select2" ).hide();
$( "#select3" ).hide();
}
else if(optvalue=="2"){
$( "#select2" ).show();
$( "#select1" ).hide();
$( "#select3" ).hide();
}
else{
$( "#select3" ).show();
$( "#select1" ).hide();
$( "#select2" ).hide();
}
}
</script>
</head>
<body>
<div id="one">
<select name="" id="select1" onchange="showlist(this.value)">
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
</select>
</div>
<div id="two">
<select name="" id="select2"
style="display: none"
onchange="showlist(this.value)">
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
</select>
</div>
<div id="three">
<select name="" id="select3"
style="display: none"
onchange="showlist(this.value)">
<option value="1"></option>
<option value="2"></option>
<option value="3"></option>
</select>
</div>
<script>
$( document ).ready( function()
{
//这是onclick事件可能有些不兼容,不推荐使用
/*var sel = $( "select" );
var option = sel.children();
console.log( option );
for( var i = 0; i < option.length; i++ )
{
option[ i ].onclick = function()
{
alert( this.value );
if( this.value ==1 )
{
$( "#select1" ).show();
$( "#select2" ).hide();
$( "#select3" ).hide();
}
else
if( this.value ==2 )
{
$( "#select2" ).show();
$( "#select1" ).hide();
$( "#select3" ).hide();
}
else
{
$( "#select3" ).show();
$( "#select1" ).hide();
$( "#select2" ).hide();
}
}
}*/
} );
</script>
</body>
</html>

最新文章

  1. 4,4s屏幕过渡页处理
  2. SQL(触发器)
  3. RTX二次开发(一)(基于ASP.NET)
  4. 【转】Python中的GIL、多进程和多线程
  5. linux下解决端口被占用的问题
  6. gettimeofday() 获取系统时间,精确到微秒 这个似乎只能在linux 下用,不能在windows 下用
  7. Android仿微信SlideView聊天列表滑动删除效果
  8. 无限的路_hdu_2073(AC).java
  9. 链表c语言实现
  10. MVP社区巡讲
  11. 如何成为一名优秀的UI设计师
  12. Eclipse设置新建jsp文件默认模板
  13. spring boot sharding-jdbc实现分佈式读写分离和分库分表的实现
  14. 使用FreeMarker生成word文档
  15. mui.init方法配置
  16. http状态码204/206/200/302/303/307
  17. webpack相关配置
  18. SEO工作中如何增加用户体验?10个细节要注意!
  19. android 下的网络图片加载
  20. LUA 表排序

热门文章

  1. HTTP学习记录:二、请求方法
  2. application.events 识别组合键 参考。
  3. Java面试题全集(中)
  4. ARTS挑战
  5. Golang基础(3):数组,切片和字典
  6. linux常用终端指令+如何用vim写一个c程序并运行
  7. tensorflow学习之Saver保存读取
  8. 一个实用的iptables脚本(各种过滤写法参考)
  9. [转帖]linux screen 命令详解,xshell关掉窗口或者断开连接,查看断开前执行的命令
  10. Centos中使用Docker部署Apollo