HTML与JavaScript交互 - 初级操作

Add a mouse interaction

 

<!doctype html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <title>FIT1050 Web Fundamentals - Week 9</title>
    <link href="style.css" type="text/css" rel="stylesheet" media="screen">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

    <script>
      function showMessage() {
        alert("JaveScript!")
      }
    </script>
    
  </head>

  <body>
    
    <h1>FIT1050 Web Fundamentals</h1>
    <h2>Week 9 - JavaScript and jQuery</h2>
    
    <p id="filters">
      Filter:
      <button data-filter=".book, .tv, .movie, .game">All</button>
      <button data-filter=".book">Books</button>
      <button data-filter=".tv">TV</button>
      <button data-filter=".movie">Movies</button>
      <button data-filter=".game">Games</button>
    </p>
    
    <p id="products">
      <!-- images sourced from: www.bigw.com.au -->
      <img src="images/small/aclashofkings.jpg" alt="" class="book" />
      <img src="images/small/blazingsaddles.jpg" alt="" class="movie" />
      <img src="images/small/bones.jpg" alt="" class="tv" />
      <img src="images/small/captainamerica.jpg" alt="" class="movie" />
      <img src="images/small/chappie.jpg" alt="" class="movie" />
      <img src="images/small/criminalminds.jpg" alt="" class="tv" />
      <img src="images/small/doctorwho.jpg" alt="" class="tv" />
      <img src="images/small/fifa16.jpg" alt="" class="game" />
      <img src="images/small/fullhouse.jpg" alt="" class="tv" />
      <img src="images/small/gameofthrones.jpg" alt="" class="tv" />
      <img src="images/small/goldenlion.jpg" alt="" class="book" />
      <img src="images/small/gosetawatchman.jpg" alt="" class="book" />
      <img src="images/small/gtav.jpg" alt="" class="game" />
      <img src="images/small/halo5.jpg" alt="" class="game" />
      <img src="images/small/makeme.jpg" alt="" class="book" />
      <img src="images/small/monstersinc.jpg" alt="" class="movie" />
      <img src="images/small/nba2k16.jpg" alt="" class="game" />
      <img src="images/small/plentymore.jpg" alt="" class="book" />
      <img src="images/small/pulpfiction.jpg" alt="" class="movie" />
      <img src="images/small/sims4.jpg" alt="" class="game" />
    </p>
    
    <script src="script.js">
      // showMessage()
    </script>
    
  </body>
  
</html>
document.querySelector('h1').addEventListener('click',showMessage);

 

Implementing interactivity with jQuery

<!doctype html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <title>FIT1050 Web Fundamentals - Week 9</title>
    <link href="style.css" type="text/css" rel="stylesheet" media="screen">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="script.js"></script>
    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  </head>

  <body>
    
    <h1>FIT1050 Web Fundamentals</h1>
    <h2>Week 9 - JavaScript and jQuery</h2>
    
    <p id="filters">
      Filter:
      <button data-filter=".book, .tv, .movie, .game">All</button>
      <button data-filter=".book">Books</button>
      <button data-filter=".tv">TV</button>
      <button data-filter=".movie">Movies</button>
      <button data-filter=".game">Games</button>
    </p>
    
    <p id="products">
      <!-- images sourced from: www.bigw.com.au -->
      <img src="images/small/aclashofkings.jpg" alt="" class="book" />
      <img src="images/small/blazingsaddles.jpg" alt="" class="movie" />
      <img src="images/small/bones.jpg" alt="" class="tv" />
      <img src="images/small/captainamerica.jpg" alt="" class="movie" />
      <img src="images/small/chappie.jpg" alt="" class="movie" />
      <img src="images/small/criminalminds.jpg" alt="" class="tv" />
      <img src="images/small/doctorwho.jpg" alt="" class="tv" />
      <img src="images/small/fifa16.jpg" alt="" class="game" />
      <img src="images/small/fullhouse.jpg" alt="" class="tv" />
      <img src="images/small/gameofthrones.jpg" alt="" class="tv" />
      <img src="images/small/goldenlion.jpg" alt="" class="book" />
      <img src="images/small/gosetawatchman.jpg" alt="" class="book" />
      <img src="images/small/gtav.jpg" alt="" class="game" />
      <img src="images/small/halo5.jpg" alt="" class="game" />
      <img src="images/small/makeme.jpg" alt="" class="book" />
      <img src="images/small/monstersinc.jpg" alt="" class="movie" />
      <img src="images/small/nba2k16.jpg" alt="" class="game" />
      <img src="images/small/plentymore.jpg" alt="" class="book" />
      <img src="images/small/pulpfiction.jpg" alt="" class="movie" />
      <img src="images/small/sims4.jpg" alt="" class="game" />
    </p>
    
    <script src="script.js">
      swal("Hello world!");
    </script>
    
  </body>
  
</html>
$( 'button' ).click( filterItems );
function filterItems() {
    let button = this;
    let selector = $( button ).data( 'filter' );
    console.log( selector );
    $('#products img').not(selector).hide(500);
    $(selector).show(500);
    // $( '#products img' ).not( selector ).fadeIn(800);
    // $( selector ).fadeOut(800);
    // $('#products img').not(selector).slideDown();
    // $(selector).slideUp();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值