怎么实现鼠标点击input输入框弹出一个日期选择框
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么实现鼠标点击input输入框弹出一个日期选择框相关的知识,希望对你有一定的参考价值。
最简单的方式就是使用H5里提供的新属性,用法如下:
<input type="date" >
如果你的项目里不支持H5或者H5不适用,就只能自己用JS来实现了
<!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" />
<script type="text/javascript" src="../js/showdate.js"></script>
<title>js点击input弹出时间选择器代码 - xw素材网</title>
<style>
.text_time
width: 207px;
height: 35px;
background: #ffffff;
border: 1px solid #56da9e;
</style>
</head>
<body>
<br>
<div style="width:520px;margin:0 auto;">
<input type="text" id="time" value="选择时间" onClick="return Calendar(\'time\');" class="text_time" />
</div>
</div>
</body>
</html>
关键是要引入showdate.js,你必须先下载showdate.js,再在项目中引入这个JS外部文件才会生效。 参考技术A
<!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>点击text文本框弹出日期选择器</title>
<!--可无视-->
<style type="text/css">
bodymargin:0;padding:0;font:14px Verdana, Arial, sans-serif;line-height:200%;
#contentpadding-left:50px;padding-right:50px;
#content h2font-size:18px;color:#1E9300;padding-top:8px;margin-bottom:8px;
#content h3margin-top:8px;margin-bottom:8px;FONT:bold 14px 宋体,tahoma,arial,sans-serif;COLOR:#0033CC;
#content divmargin-top:10px;margin-bottom:10px;border:#666 solid 1px;padding:10px;
#content spancolor:#f00;font-weight:bold;
ul, olcolor:#000000;
</style>
<!--必要js文件/样式表已经引入在js里面了-->
<script type="text/javascript" src="lhgcore.js"></script>
<script type="text/javascript" src="lhgcalendar.js"></script>
</head>
<body>
<div id="content">
<h2>常规弹出日历示例页</h2>
<hr size="1" style="width:400px;" align="left">
<h3>1. 在控件下面或右面弹出日历组件(默认是在下面弹出) </h3>
<div>
<input type="text" id="c1" onclick="J.calendar.get();"/> 显示在下面
<input type="text" id="c2" onclick="J.calendar.get(dir:'right');"/> 显示在右面
</div>
<h3>2. 通过按钮或图片等其它控件弹出日历组件</h3>
<div>
<input type="text" id="c3"/>
<input type="button" id="btn" onclick="J.calendar.get(id:'c3');" value="弹出"/>
<input type="text" id="c4"/>
<img align="absmiddle" src="images/date.gif" onclick="J.calendar.get(id:'c4');"/>
</div>
<h3>3. 显示日期的2种格式(默认为 年-月-日 格式)</h3>
<div>
<input type="text" id="c5" onclick="J.calendar.get();"/> 年-月-日 格式
<input type="text" id="c6" onclick="J.calendar.get(type:'/');"/> 月/日/年 格式
</div>
<h3>4. 在文本框显示带时间的日期</h3>
<div>
<input type="text" id="c7" onclick="J.calendar.get(time:true);"/>
</div>
<h3>5. 日期范围限制</h3>
<div>
<input type="text" id="c8" onclick="J.calendar.get(to:'2009-8-8,min');"/> 只能选择2009-8-8以前的日期
<input type="text" id="c9" onclick="J.calendar.get(to:'2009-8-18,max');"/> 只能选择2009-8-18以后的日期<br/>
<input type="text" id="c10" onclick="J.calendar.get(to:'c11,min');"/>
<input type="text" id="c11" onclick="J.calendar.get(to:'c10,max');"/> 这2个文本框,前面的日期不能大于后面的日期,后面的不能小于前面的日期。
</div>
</div>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
</div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="http://www.my97.net/dp/My97DatePicker/WdatePicker.js"></script>
</head>
<body>
<input type="text" id="d11" onclick="WdatePicker()">
</body>
</html>
导入js直接使用,具体详细使用可参考文档
html5页面当点击input输入框弹出安卓手机上键盘就会把背景顶了上来,页面布局就乱了,求帮助
<style>
.trueBg01
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 50%;
.trueBg02
position: absolute;
top: 50%;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 90%;
background-image: url(../../../../Assets/img/trueBg02.jpg);
background-repeat: repeat-y;
background-size: 100%;
.trueBg03
position: absolute;
top: 105%;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 40%;
</style>
<div class="trueBg01">
<img src="../../../../Assets/img/trueBg01.jpg"/>
</div>
<div class="trueBg02"></div>
<div class="trueBg03">
<img src="../../../../Assets/img/trueBg03.jpg"/>
</div>
<div style="position: relative; padding-top:80%;">
<button >确 定</button>
</div>
在安卓手机上button的背景不在图片的下面、背景变成了白色,,苹果手机上没事。求解决方法!!
解决方法
1、scrollIntoView(alignWithTop): 滚动浏览器窗口或容器元素,以便在当前视窗的可见范围看见当前元素。
2、alignWithTop 若为 true,或者什么都不传,那么窗口滚动之后会让调用元素的顶部与视口顶部尽可能平齐。
3、alignWithTop 若为 false,调用元素会尽可能全部出现在视口中,可能的话,调用元素的底部会与视口顶部平齐,不过顶部不一定平齐。
4、该方法是唯一一个所有浏览器都支持的方法,类似还有如下方法,但是只有在Chrome和Safari有效。
5、代码如下:
6、再次测试,效果如下:
7、相比于input被挡住,突兀地出现在页面中间更加可以令人接受,但是多次测试,仍然存在问题:当切换输入法的时候,input框的位置会往下移动,被键盘挡住一部分,而且出现的概率比较高(中英文切换),效果如下:
8、当软键盘被唤起是,使用 scrollTop() 方法使input元素滚动到指定的位置,但是滚动的具体数值需要调试才能给出,所以这里就不再演示了。
参考技术A 应该是高度影响的,你的继承高度用的外层需要重新定义一次高度,例如你原本写的是100%
你的显示屏幕高度为800px;
你页面加载完成之后,要给外层一个800px的高度,这样键盘就不会定上去了 参考技术B $(function()
$('body').height($('body')[0].clientHeight);
);
这句加上即可 参考技术C 可以在body中加个min-height
以上是关于怎么实现鼠标点击input输入框弹出一个日期选择框的主要内容,如果未能解决你的问题,请参考以下文章
vue elementUI点击输入框弹出弹窗不允许输入框输入