3、jQuery知识点

1、JavaScript和jQuery库

jQuery库:里面存在大量的JavaScript函数

在线的jQuery(CDN)

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

jQuery公式: $(selector选择器).action,选择器就是CSS的选择器

初识jQuery

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
</head>
<body>
<!--  公式: $(selector选择器).action -->
<a href="" id="test_jquery">点我</a>

<script>
    $('#test_jquery').click(function () {
        alert('hello jquery');
    })
</script>

</body>
</html>

2、jQuery选择器

css中的选择器在jQuery中也可以使用

    $('p').click();// 标签选择器
    $('#id').click(); // id选择器
    $('.class').click();// class选择器

3、jQuery事件

鼠标事件,键盘事件

鼠标事件:

  • mousemove 移动鼠标
  • mousedown 按下鼠标
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
    <style>
        #divmove{
            width: 500px;
            height: 500px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
mouse:  <span id="mouseMove"></span>
<div id="divmove">
    移动鼠标试试
</div>

<script>
    $(function () {
        $('#divmove').mousemove(function (e) {
            $('#mouseMove').text('x:' +e.pageX + 'y:' +e.pageY)
        })
    })
</script>
</body>
</html>

3、jQuery操作DOM元素

	节点文本操作
	//获得值
	$('#test-ul li[id=java]').text();
	//设置值
	$('#test-ul li[id=java]').text('设置值');
	//获得值
	$('#test-ul ').html();
	//设置值
	$('#test-ul ').html('<strong>123</strong>');
	css的操作
	$('#test-ul li[id=java]').css("color","red")
	元素的隐藏和显示   

本质:display:none

	// 显示
	$('#test-ul li[id=java]').show()
	// 隐藏
	$('#test-ul li[id=java]').hide()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值