select下拉菜单与button的互动选择
来源:互联网 发布:suse yum源配置 编辑:程序博客网 时间:2024/06/05 18:08
<!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>select下拉菜单与button的互动选择</title><script src="http://apps.bdimg.com/libs/jquery/2.0.0/jquery.min.js"></script><style>select{ width:100px; height:30px; line-height:30px; border:#ccc 1px solid; border-radius:3px;}.btn{width:100px; height:30px; line-height:30px; background:#333; color:#fff; border:none; border-radius:3px;}.btn.xuanz{ background:#09F;}</style></head><body> <label for="caidan"></label> <select name="caidan" id="caidan"> <option>温江区</option> <option>双流区</option> <option>龙泉驿区</option> <option>新都区</option> <option>郫县</option> <option>青白江区</option> </select> <button class="btn">温江区</button> <button class="btn">双流区</button> <button class="btn">龙泉驿区</button> <button class="btn">新都区</button> <button class="btn">郫县</button> <button class="btn">青白江区</button><script>/*法一、var ablumlistnumeber=$("#caidan option").length;$("#btn1").addClass("xuanz");for(i=0; i<ablumlistnumeber;i++){$("#btn"+(i+1)).click(function(){ var cityname=$(this).val(); $(this).siblings().removeClass("xuanz"); $(this).addClass("xuanz"); $("#caidan").children("option").each(function() {if($(this).text()==cityname){$(this).siblings().removeAttr("selected");$(this).attr("selected",true).prop("selected",true);//$(this).attr("selected",true).siblings().removeAttr("selected");} })})}$("#caidan").change(function(){//if($(this).find("option:selected")){var xh=$(this).children("option:selected").index();$("#btn"+(xh+1)).siblings().removeClass("xuanz");$("#btn"+(xh+1)).addClass("xuanz");//}})*/</script><script>//法二、$(".btn").eq(0).addClass('xuanz')$(".btn").click(function(){$(this).addClass('xuanz').siblings('.btn').removeClass('xuanz')$("#caidan").find("option").eq($(".btn").index($(this))).prop("selected",true) //$(this).index() 也可以找下标,prop和attr效果是一样的,无太大区别})$("#caidan").change(function(){alert($('#caidan option').index($('#caidan option:selected')))//获取索引$(".btn").eq($('#caidan option').index($('#caidan option:selected'))).addClass('xuanz').siblings('.btn').removeClass('xuanz')})</script></body></html>
转载于:http://www.qdfuns.com/notes/22982/fcfce883a7f481aa3d8731bf7b8a340f.html
阅读全文
1 0
- select下拉菜单与button的互动选择
- 如何设置Select下拉选择框(菜单)的样式
- javascript自动查找select下拉的菜单并选择
- js自动查找select下拉的菜单并选择
- 实现select自动选择下拉菜单的值
- select与datalist在制作下拉菜单时的区别
- Atitit.ui控件---下拉菜单选择控件的实现select html
- 下拉菜单select值的获得
- select下拉菜单的高度 改变
- ruby中的下拉菜单select的写法
- 基于Jquery的模拟Select下拉菜单
- 如何动态的添加下拉菜单跟复选框及submit与button的使用差别
- select下拉菜单问题
- js select 下拉菜单
- select下拉菜单美化
- 下拉列表select的联动选择
- javascript 下拉框(select)选择与被选择
- 下拉选择菜单Spinner的使用
- 安卓jarsigner签名安装包
- CO乱象调查:定价随意 暴富诱惑已揽入社区大妈
- 数据库视频总结
- Scott建表语句
- Mybatis连接mysql,数据库中字符乱码问题
- select下拉菜单与button的互动选择
- OC : NSException (崩溃)
- mybatis的jdbctype映射问题
- 第四十一篇: JAVA读取图像metadata信息
- IAR常见段名含义
- Linux-函数-小节
- 免费使用的pdf转cad软件使用
- dom4j解析xml字符串实例
- Linux ES集群服务配置说明