jQuery笔记

jQuery

1.jQuery初始

JavaScript和jQuery的关系
jQuery相当于JavaScript封装的库
获取jQuery

jQuery API文档
https://jquery.cuishifeng.cn/
jQuery公式

$(selector).action() //公式

例子:

<a href="#" id="test">点我</a>
<script>
    //选择器时css的选择器
    $('#test').click(function(){
        alert('hello,jQuery')
    })
</script>

2.jQuery选择器

  • css种的选择器jQuery都能用

3.事件

  • 鼠标事件,键盘事件,其他事件

获取鼠标坐标


<body>
mouse: <span id="mousemove"></span>
<div id="divmove">
在这里移动试试
</div>
<script>
    $(fuction){
        $('#divmove').mousemove(function(e){
            $('#mousemove').text('x:'+e.pageX + 'y:'+e.pageY)
    })
    }
</script>
<body>

4.操作DOM

节点文本操作

$('#test').text('abc')
$('#test').html('<strong>abc</strong>')

css操作

$('#test').css({"color","red"})

元素显示和隐藏

//display: none;
$('#test').show()
$('#test').hide()
posted @ 2021-05-13 19:22  danxibao_chen  阅读(44)  评论(0)    收藏  举报