网页加载的不同的方式、点击按钮显示一句话、jQuery中获取元素的方法
生活随笔
收集整理的這篇文章主要介紹了
网页加载的不同的方式、点击按钮显示一句话、jQuery中获取元素的方法
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
網(wǎng)頁加載的不同的方式
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title><script src="jquery-1.12.1.js"></script><script>// 點擊按鈕,顯示一句話// $("#btn").click(function(){// console.log('小蘇好帥哦');// });// 沒有頁面加載的事件// 注冊事件----賦值的// DOM中頁面加載事件----頁面全部加載完畢才觸發(fā)(標(biāo)簽,文字,圖片,引入的文件)// window.onload = function(){// console.log('小蘇好帥');// };// window.onload = function(){// console.log('哈哈,我又變帥了');// };// jQuery的代碼// 頁面加載事件// jQuery中第一種頁面加載事件// $(window).load(function(){// console.log('小蘇好猥瑣哦');// });// $(window).load(function(){// console.log('哈哈,小楊好帥哦');// });// jQuery中第二種頁面加載的事件----比上面的快----頁面中的基本的元素加載后// 就觸發(fā)了// $(document).ready(function(){// console.log(1);// });// $(document).ready(function(){// console.log(2);// });// jQuery中第三種頁面加載的事件----頁面中基本的元素加載后就觸發(fā)了// jQuery(function(){// console.log('頁面加載了1');// });// jQuery(function(){// console.log('頁面加載了2');// });// $(document).ready(function(){// console.log(1);// });// $(document).ready(function(){// console.log(2);// });$(function(){console.log('頁面加載了1');});$(function(){console.log('頁面加載了2');});// function f1(){// }// f1();// f1();</script> </head> <body> <input type="button" value="顯示效果" id="btn"><script>// document.getElementById('btn').onclick = function(){// console.log(1);// };// document.getElementById('btn').onclick = function(){// console.log(2);// };// var num = 10;// var num = 100;// console.log(num); </script> </body> </html>點擊按鈕顯示一句話
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title><script src="jquery-1.12.1.js"></script><script>// 頁面加載的事件$(function(){// 根據(jù)id獲取按鈕,添加點擊事件$("#btn").click(function(){console.log('哈哈,真的好帥');});});</script> </head> <body> <input type="button" value="顯示效果" id="btn"></body> </html>jQuery中獲取元素的方法
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Document</title><script src="jquery-1.12.1.js"></script><script>// DOM作用:操作頁面的元素/*** DOM中獲取元素的方式:** 根據(jù)id獲取元素* document.getElementById('id屬性的值');* 根據(jù)標(biāo)簽名字獲取元素* document.getElementsByTagName('標(biāo)簽名字');* 根據(jù)name屬性獲取元素* document.getElementsByName('name屬性的值');* 根據(jù)類樣式名字獲取元素* document.getElementsByClassName('類樣式的名字');* 根據(jù)選擇器獲取元素* document.querySelector('選擇器');---->id選擇器,類選擇器,標(biāo)簽選擇器...* 一個的* document.querySelectorAll('選擇器');多個的* *//*** jQuery中獲取元素的方式:** $("選擇器")----jQuery對象*/</script> </head> <body></body> </html>?
總結(jié)
以上是生活随笔為你收集整理的网页加载的不同的方式、点击按钮显示一句话、jQuery中获取元素的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery版本的网页开关灯、jQuer
- 下一篇: id选择器、标签选择器、类选择器、交集选