jQuery中的变量前面必须加上 $ ,且自带遍历功能($ 等价于 jQuery)。
<!-- 完整版jQuery -->
https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js
<!-- 压缩版jQuery -->
https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js
.html() 设置超文本内容
.val() 设置表单元素内容
.css() 设置样式
.on(“事件类型”,事件处理函数) 绑定事件
addClass("类名")添加元素类名
removeClass("类名")删除元素类名
hasClass("类名" )判断有没有类名
toggleClass("类名")切换类名,原先有就删除,没有就添加
// jQuery绑定
$('.jq').click(function(){
alert('我是jQuery1')
})
$btn.click(function(){
alert('我是jQuery2')
})
jQuery('.jq').click(function(){
alert('我是jQuery3')
})
$('.jq').on('click',function(){
alert('我是jQuery4')
})