1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Events</title> <script src="../jquery-3.4.1.min.js"></script> <style> body { font-size: 17px; font-family: Arial; background: #f4f4f4; line-height: 1.5em; }
header { background: #333333; color: #fff; padding: 20px; text-align: center; border-bottom: 4px #000 solid; margin-bottom: 10px; }
#container { width: 90%; margin: auto; padding: 10px; } </style> </head>
<body> <header> <h1>jQuery Crash Course | Events</h1> </header> <div id="container"> <h1>Mouse Events</h1> <button id="btn1" class="btnClass">Button 1</button> <button id="btn2">Button 2</button> <button id="buttoncgbk">Buttoncgbk</button> <p class="para1"> Wikipedia is hosted by the Wikimedia Foundation, a non-profit organization that also hosts a range of other projects. Wikipedia apps are now available: Download for iOS on the App Store Download for Android on Google Play View full list of available Wikipedia apps </p> <form id="form"> <label>Name</label> <br> <input type="text" id="name" name="name"> <br> <label>Email</label> <br> <input type="email" id="email" name="email"> <br> <label>Gender</label> <select id="gender" name="gender"> <option value="male">Male</option> <option value="female">Female</option> </select><br> <input type="submit" value="Submit"> </form> </div> <script> $(document).ready(function () {
$('#btn1').click(function () { alert('Button Clicked!'); });
$('#btn1').on('click', function () { alert('Button Clicked!'); });
$("#buttoncgbk").toggle(function () { $("body").css("background-color", "green"); }, function () { $("body").css("background-color", "red"); }, function () { $("body").css("background-color", "yellow"); } );
$('#btn1').on('click', function () { $('.para1').toggle(); }); $('#btn2').on('click', function () { $('.para1').show(); });
$('#btn1').dblclick(function () { $('.para1').toggle(); });
$('#btn2').hover(function () { $('.para1').toggle(); }); $('#btn1').on('mousemove', function () { $('.para1').toggle(); });
$('#btn1').on('mousedown', function () { $('.para1').toggle(); }); $('#btn1').on('mouseup', function () { $('.para1').toggle(); });
$('#btn1').click(function (e) { alert(e.currentTarget.className); });
$(document).on('mousemove', function (e) { $('#coords').html('Cooeds Y:' + e.clientY + 'X:' + e.clientX); });
$('input').focus(function () { $(this).css('background', 'silver'); }); $('input').blur(function () { $(this).css('background', 'white'); }); $('input').keyup(function (e) { console.log(e.target.value); });
$('select#gender').change(function (e) { alert(e.target.value); }); $('#form').submit(function (e) { e.preventDefault(); var name = $('input#name').val(); console.log(name); });
}); </script> </body> </html>
|