博主信息
博文 9
粉丝 0
评论 0
访问量 6682
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
jQuery基础练习--春节倒计时-2019.01.22
大宝的博客
原创
706人浏览过

一、jQuery选择器的进本用法

实例

<!DOCTYPE html>
<html>
<head>
  <title>练习</title>
   <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
   <style type="text/css">
     .box{width: 200px;height: 200px;
              background: pink;text-align:center;
              line-height: 200px;margin-bottom: 10px;
          }
     textarea{width: 400px;
             height: 200px;
             border-radius: 6px;
             outline:none; /*去掉文本框再带获得焦点样式*/
             resize:none;/*当resize的属性为none时,则禁止拖动*/
          }
   </style>
   <script>
   	   $(function(){
            //class选择器  
            $('.btn').click(function(){
                $('.box').hide();
            })
            //id选择器 
            $('#btn').click(function(){
                $('.box').show(100);
            })
            //类型选择器 选取 class 为 into 的 <button> 元素
            $("button.into").click(function(){
   	   	 		$('.box').text('惊喜不!')
   	   	 	})
            // $(this) 选取当前 HTML 元素
            $('p').click(function(){
                  $(this).text('~惊喜不~').css('background','#ff6500')
            })
            // $("*") 选取所有元素              
            $('#hide').click(function(){
                  $('*').hide()
            }) 
            //文本框获得焦点事件
            $("textarea").focus(function(){
                $(this).css("border","1px solid red");
            })
            $("textarea").blur(function(){
                $(this).css("border","1px solid #ccc");
            }) 
        })
   </script>
</head>
<body>  
 <div class="box" style="">
   ~ hello!! ~
 </div>
 <button class="btn">点我隐藏</button> 
 <button id="btn">点我显示</button> 
 <button class="into">点我有惊喜</button>
 <p style="width: 200px;height: 200px;background: pink;text-align:center;line-height: 200px;"> ~ hello!! ~</p>
 <form>
      <textarea></textarea>
 </form>
 <button id="hide">清空页面</button> 
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

二、春节倒计时

实例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
	</head>
	<style type="text/css">
		.content{width: 80%; height: 350px; margin: 0 auto; }
	</style>
	<body>
		<div class="content">
			<div class="timespan">
				
			</div>
		</div>
	</body>
	<script type="text/javascript">
		var starttime= new Date("2019/02/04"); 
		setInterval(function(){
			var nowtime=new Date();
			var time= starttime-nowtime ;
			 var day = parseInt(time / 1000 / 60 / 60 / 24);    
			 var hour = parseInt(time / 1000 / 60 / 60 % 24);     
			 var minute = parseInt(time / 1000 / 60 % 60);    
			 var seconds = parseInt(time / 1000 % 60); 
			$('.timespan').html("2019年春节倒计时"+day+"天"+hour+"小时"+minute+"分钟"+seconds+"秒")
		})
		$(function(){
			$('.content').css('background','pink')
		    $('.timespan').css({"color":"#fff","padding-top":"100px","text-align":"center","font-size":"50px"})
		})
	</script>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学