首页 技术 正文
技术 2022年11月21日
0 收藏 756 点赞 3,026 浏览 2557 个字

本文为博主原创,未经允许不得转载:

jQuery提供了很多很强大的事件,想要都掌握发现难度蛮大的,只有在不断的应用与实践中学习和掌握。

在做页面的时候,想做一个在选择下拉框选择值的时候,系统根据下拉框选择的值,自动触发先前定义的事件。

本想自己写一个原生的事件来实现,想起来jQuery提供了一个自动触发的事件onchange(),可以在下拉框选择的值

改变的同时,触发定义的事件。

示例如下:

要实现当下拉框中选择按月查询时,后面显示对应按月条件进行查询的按钮,

当下拉框选择按日查询时,后面显示对应按日期条件进行查询的按钮,

onchange()事件的应用

onchange()事件的应用

代码如下:

<div class="col-md-6">
<div class="form-group col-md-1"></div>
<div class="form-group col-md-2">
<div class="col-md-12">
<!--onchange="show(this.value)" 该事件对应下拉列表值,并触发show事件,对应显示在show事件中定义-->
<select id="selectCondition" class="form-control" onchange="show(this.value)" style="padding-left: 0px; padding-right: 0px; border-right-width: 0px;border-left-width: 0px;border:1px solid #ccd0d4;">
<option value="" selected="">按月查询</option>
<option value="">按日查询</option>
</select>
</div>
</div>
<!-- 按月查询div -->
<div class="col-md-9" id="monthConditionDiv">
<div class="form-group col-md-3">
<div class="col-md-12">
<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-white ">最近一个月</a>
</div>
</div>
<div class="form-group col-md-3">
<div class="col-md-12">
<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-white ">三个月</a>
</div>
</div>
<div class="form-group col-md-3">
<div class="col-md-12">
<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-white ">六个月</a>
</div>
</div>
<div class="ant-form-item-control-wrapper col-md-3 input-group">
<div class="ant-form-item-control ">
<span class="ant-calendar-picker" style="width: 100%;">
<div style="padding-top: 15px;">
<input readonly="" value="" placeholder="自定义" class="ant-calendar-picker-input ant-input" />
<span class="ant-calendar-picker-icon" style="margin-top: 0;"></span>
</div>
</span>
</div>
</div>
</div>
<!-- 按日查询div -->
<div class="col-md-9" id="dayConditionDiv" style="display:none;">
<div class="form-group col-md-3">
<div class="col-md-12">
<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-white ">昨日</a>
</div>
</div>
<div class="form-group col-md-3">
<div class="col-md-12">
<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-white ">最近三天</a>
</div>
</div>
<div class="form-group col-md-3">
<div class="col-md-12">
<a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-white ">最近一周</a>
</div>
</div>
<div class="ant-form-item-control-wrapper col-md-3 input-group">
<div class="ant-form-item-control ">
<span class="ant-calendar-picker" style="width: 100%;">
<div style="padding-top: 15px;">
<input readonly="" value="" placeholder="自定义" class="ant-calendar-picker-input ant-input" />
<span class="ant-calendar-picker-icon" style="margin-top: 0;"></span>
</div>
</span>
</div>
</div>
</div> </div>
<!-- javascript 中定义show事件 -->
<script type="text/javascript">
var selectConValue = $("#selectCondition option:selected").val();
function show(flag){
if(flag==1){
$("#monthConditionDiv").hide();
$("#dayConditionDiv").show();
}
if(flag==30){
$("#monthConditionDiv").show();
$("#dayConditionDiv").hide();
}
} </script>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919