第一步:先建立一个html网页,如下:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title></title>
 </head>
 <body>
  <div>
   <div>
        <input class="btnhy1" type="button" value="一楼" style="width: 80px;height: 30px; border: 2px; background: #2290E0;"/>
       <input class="btnhy2" type="button" value="二楼" style="width: 80px;height: 30px; border: 2px; background: #2290E0;"/>
     </div>
    <div>
        <img ></script>
 </body>
</html>

需要注意的是:index.js使用“$”时,必须要引用“ <script src="./js/jquery-1.8.3.min.js"></script>”,要不然就会报 “Uncaught ReferenceError: $ is not defined”错误,如果引用的路径不对就会报:“Failed to load resource: net::ERR_FILE_NOT_FOUND”

第二步:编写index.js的代码,代码如下:

$(".btnhy1").click(function() {
 //alert("111")
 $("#image1").show();
 $("#image2").hide();
});
$(".btnhy2").click(function() {
 //alert("222")
 $("#image2").show();
 $("#image1").hide();
});
 
总结:class  使用的是.(dot),id使用的是#。

 

相关文章:

  • 2021-07-21
  • 2021-09-22
  • 2021-07-07
  • 2022-12-23
  • 2022-02-09
  • 2021-04-16
  • 2022-12-23
  • 2021-12-12
猜你喜欢
  • 2022-12-23
  • 2021-12-27
  • 2022-02-07
  • 2021-09-25
  • 2021-12-23
  • 2022-02-21
  • 2022-12-23
相关资源
相似解决方案