zoukankan      html  css  js  c++  java
  • 编写html与js交互网页心得:编写两个按钮切换显示不同的图片

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

    <!DOCTYPE html>
    <html>
     <head>
      <meta charset="utf-8" />
      <title></title>
     </head>
     <body>
      <div>
       <div>
            <input class="btnhy1" type="button" value="一楼" style=" 80px;height: 30px; border: 2px; background: #2290E0;"/>
           <input class="btnhy2" type="button" value="二楼" style=" 80px;height: 30px; border: 2px; background: #2290E0;"/>
         </div>
        <div>
            <img id="image1" src="img/111.jpg"/>
          <img id="image2" src="img/222.jpg"/>
        </div>
      </div>
      
      <script src="./js/jquery-1.8.3.min.js"></script>
      <script src="./js/index.js"></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使用的是#。
  • 相关阅读:
    python安装requests
    Python多线程基本操作
    Python连接mysql基本操作
    Python中文问题
    Python 3.6.5 导入pymysql模块出错:No module named 'pymysql'
    python安装pyMysql
    HTML, CSS. JS的各种奇葩bug
    css移动元素的几种方法
    三张图看懂 clientheight、offsetheight、scrollheight
    伪类和伪元素的区别
  • 原文地址:https://www.cnblogs.com/wlming/p/10198206.html
Copyright © 2011-2022 走看看