首页 > Web开发 > 详细

Jquery基础,点击事件click,鼠标移入事件mouseover。通过事件改变DOM结构

时间:2021-09-12 01:22:09      阅读:39      评论:0      收藏:0      [点我收藏+]

直接上代码,复制粘贴就可以跑,注意最外面有一层$(function(){

})  包住的。jQuery代码在<script></script>里面,要把注销去掉。一个一个看效果

+Tenus One <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags must come first in the head; any other head content must come after these tags -->
    <title>Bootstrap 101 Template</title>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <style type="text/css">

  .jumbotron {text-align: center;}
  </style>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn‘t work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
<div class="container">
  <div class="jumbotron">
    <h1>Let‘s have Fun</h1>      
    <button type="button" id="btn1" class="btn btn-default">#btn1</button>
    <button type="button" id="btn1" class="btn btn-default">#btn2</button>
    <button type="button" id="btn1" class="btn btn-default">#btn3</button>
    <button type="button" id="btn1" class="btn btn-default">#btn4</button>
  </div>
  <div class="col-xs-3">
  <div id="panel1" class="panel panel-primary">
  <div class="panel-heading">
   #panel1
  </div>
  <div class="panel-body"> Contet 
  </div>

  </div>
  </div>
  <div class="col-xs-3">
  <div id="panel2" class="panel panel-primary">
  <div class="panel-heading">
   #panel2
  </div>
  <div class="panel-body"> Contet 
  </div>

  </div>
  </div>
  <div class="col-xs-3">
  <div id="panel3" class="panel panel-primary">
  <div class="panel-heading">
   #panel3
  </div>
  <div class="panel-body"> Contet 
  </div>

  </div>
  </div>
  <div class="col-xs-3">
  <div id="panel4" class="panel panel-primary">
  <div class="panel-heading">
   #panel4
  </div>
  <div class="panel-body"> Contet 
  </div>

  </div>
  </div>
    <!-- jQuery (necessary for Bootstrap‘s JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <!-- <script src="js/bootstrap.min.js"> -->
<script type="text/javascript">
	$(function(){
		// $("#btn1").on(‘click‘,function(){
		// 	$("#panel1").slideToggle(200);
		// });  点击按钮下面面板隐藏
		
		// $("#panel1").on(‘click‘,function(){
		// 	$("#panel1").fadeOut(200);
		// });  自己点击自己淡出
		
		// $("#btn1").on(‘mouseover‘,function(){
		// 	$("#panel1").fadeToggle(200);
		// }); 
		 // 点击事件click改成了鼠标移入mouseover事件
		
		// $("#btn1").on(‘click‘,function(){
		// 	$("#panel1 .panel-body").html(‘my is new panel‘);
		// });
		// 点击click事件通过html(),在.panel-body类的html标签插入新的内容
		
		
		// $("#btn1").on(‘click‘,function(){
		// 	$("#panel1").toggle();
		// });
		// 这个toggle相当于show跟hide的结合,点击一次显示再点击隐藏
		
	})
</script>
    

  
  </body>
</html>

  

Jquery基础,点击事件click,鼠标移入事件mouseover。通过事件改变DOM结构

原文:https://www.cnblogs.com/hechunfeng/p/15249684.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!