在页面加载时弹出提示框
效果:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
<script>
// 标准写法
// $(document).ready(()=>{
// alert('hello, jQuery!')
// })
// 简写
$(()=>{
alert('hello, JQuery!')
})
</script>
</body>
</html>
dom对象转换为Jquery对象
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>
<body>
<input type="button" onclick="btnClick()" id="btn" value="我是按钮" />
<script>
const btnClick = ()=>{
// dom对象转JQuery对象
var btnEl = document.getElementById('btn')
var $btn = $(btnEl)
console.log($btn.val())
// JQuery对象转dom对象
// var $btn = $('#btn')[0]
// console.log($btn.value)
}
</script>
</body>
</html>