Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Penerapan jQuery Event pada Mouse, Keyboard dan Form</title>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
- </head>
- <body>
- <h1>Halo, Selamat Datang di Gamelab!</h1>
- <div id="myDiv" style="width: 200px; height: 200px; background-color: lightblue;">Arahkan kursor mouse ke sini</div>
- <br>
- <button id="myButton">Klik Saya</button>
- <input type="text" id="myInput" placeholder="Ketik sesuatu di sini">
- <p id="hasil_input"></p>
- <form id="myForm">
- <label for="nameInput">Nama:</label>
- <input type="text" id="nameInput"><br>
- <label for="emailInput">Email:</label>
- <input type="email" id="emailInput"><br>
- <input type="submit" value="Submit">
- </form>
- <p id="hasil_form"></p>
- <script>
- $(document).ready(function () {
- //Penerapan untuk tag h1
- $("h1").css("color", "blue");
- //Penerapan Event Mouseenter dan Mouseleave
- $("#myDiv").mouseenter(function () {
- $(this).text("Kursor Mouse berada di dalam");
- });
- $("#myDiv").mouseleave(function () {
- $(this).text("Kursor Mouse berada di luar");
- });
- //Penerapan event ketika tombol diklik
- $("#myButton").click(function () {
- alert("Tombol diklik!");
- });
- //Penerapan Event Keyboard Keypress
- $(document).keypress(function (event) {
- var key = String.fromCharCode(event.which);
- $("#hasil_input").text("Anda menekan tombol " + key);
- });
- // Penerapan Event Form submit
- $("#myForm").submit(function (event) {
- event.preventDefault(); // Menghentikan submit form
- var name = $("#nameInput").val();
- var email = $("#emailInput").val();
- $("#hasil_form").text("Nama: " + name + ", Email: " + email);
- });
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement