1.jQuery的入口函数:
2.jQuery选择标签:$(’’)
例子:
<button id="btn">隐藏</button>
<div id="box">
</div>
<style>
#box{
width: 100px;
height: 100px;
background: aquamarine;
}
</style>
<script>
$(function () {
$('#btn').click(function () {
$('#box').hide('slow')
$('#box').hide(1000)
})
})
其中hide()方法是隐藏的作用,参数可以是速度,也可以是时间。相对show()显示的方法
3.标签的选择
下面是需要添加样式的几个标签
<div id="box1">qqq</div>
<div class="box2">qqq</div>
<span> 字体大小</span>
<ul>
<li class="li1"></li>
<li class="li2"></li>
<li class="li3"></li>
</ul>
<ul>
<li class="li"></li>
<li class="li2"></li>
<li class="li3"></li>
</ul>
<style>
.newclass{
height: 100px;
width: 100px;
background: gold;
overflow: hidden;
}
</style>
添加样式的jQuery代码:
<script>
$(function () {
//增加css样式
$('#box1').css({'width':'100px','height':'100px','background-color':'blue'})
$('.box2').css({'font-size':'70px'})
//查看字体大小
console.log($('span').css('font-size'))
// 增加类名
$('.box2').addClass('newclass')
//给li标签增加内容
// $('.li1').html('这是li1')
//查找第一个ul下的第一个li标签
// $('ul li:first').html('li1')
//查找所有ul下的第一个li标签
$('ul li:first-child').html('li1')
// 通过属性值查找
// 查找name的值为pwd的input标签
console.log($('input[name="pwd"]'))
})
</script>
获得的结果: