abstrait:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jq事件</title> <script src="jquery-3.3.1.min.js"> </scrip
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>jq事件</title> <script src="jquery-3.3.1.min.js"> </script> </head> <body> <script> //語法 $('選擇器').事件(funtion(){ // $('選擇器').改變的屬性('','') }) //blur失去焦點 //focus()獲取焦點 //change 值發(fā)生變化 //click 單擊 //dblclick 雙擊 //mousemove鼠標移上 $(document).ready(function(){ // $('input').focus(function(){ // $('input').css('background','red') // }) $('input').change(function(){ $('input').css('background','pink') }) $('button').click(function(){ $('#div').css('background','blue') }) $(document).mousemove(function(xy){ $('span').text('x值:'+xy.pageX+'y:'+xy.pageY) }) }) </script> <input type="text"> <div id="div" style="width: 100px; height: 100px; background: red;margin-top: 20px;"></div> <button>點擊</button> <div> 當前鼠標的位置: <span></span> </div> </body> </html>
語法 $('選擇器').事件(funtion(){
$('選擇器').改變的屬性('屬性名','修改值') })
用到的方法 blur失去焦點,focus()獲取焦點 change 當值發(fā)生變化
click 單擊 dblclick 雙擊 mousemove鼠標移上
通過$就能獲取選擇器,語法比js要方便