????:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery事件操作</ti
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery事件操作</title> <script src="jquery-3.3.1.min.js"></script> <style> div{ margin: 0 auto; text-align: center; } #show{ width: 100px; height: 100px; background-color:seashell; } button{ margin-top:50px; } </style> </head> <body> <div> <div id="show"> </div> <input type="text" value="請(qǐng)輸入賬號(hào)"> <button type="button" id="cz" value="操作">操作</button><br> <span> 鼠標(biāo)放上來(lái)會(huì)變的</span> <div id="sbwz"> </div> </div> <script> $(document).ready(function () {//就緒函數(shù) // alert("1111"); //點(diǎn)擊事件 $('button').click(function () { var a = $('button').val(); //alert(a); if (a == '操作') { $('#show').css('background', 'red'); $('#cz').text("red").attr('value', 'red'); } else { $('#show').css('background', 'pink'); $('#cz').text("操作").attr('value', '操作'); } }) //獲取焦點(diǎn) $('input').focus(function () { $('input').attr('value',""); }); //失去焦點(diǎn) $('input').blur(function () { var a = $('input').val(); if(a == ""){ $('input').attr('value','請(qǐng)輸入賬號(hào)') } }); //鼠標(biāo)移上 $('span').mouseover(function () { $('span').css('background','red'); }); //鼠標(biāo)離開 $('span').mouseleave(function () { $('span').css('background','yellow'); }) //取鼠標(biāo)位置 $(document).mousemove(function (a) { //alert(a.pageX); $('#sbwz').text('X:'+a.pageX+'---'+'Y:'+a.pageY); }) }) </script> </body> </html>
總結(jié):事件關(guān)鍵函數(shù)不太熟悉。如果使用需要直接去找。。。。還需要加強(qiáng)記憶