--------基本选择器-------------
.imgclass
{
width:200px; height:200px;
}
.imgclass1
{
width:210px; height:210px;
}
table tr td
{
width:300px; height:300px;
}
$(function () {
$('#Button1').click(function () {
//获取的是所有类型(tagname)为img的元素
//$('img').hide(3000);
//$('img').show(3000);
//获取的是所有class属性的值为“imgclass”的元素
//$('.imgclass').hide(3000);
//$('.imgclass').show(3000);
//获取文档中的所有元素
//$('*').hide(2000);
//$('*').css('background-color', 'Blue');
//$('#img1,#img3,#Button2').hide(2000);
//$("#img1,#img3,#Button2").show(2000);//一定是将所有id用一对''括起来,而不能每个id分别用引号括起来
//多个选择器既可以是id,也可以是id,tagname和classname的混合体
//$('#img1,#img3,input').hide(2000);
//$("#img1,#img3,input").show(2000);
})
//改变图片样式
$('#Button2').click(function () {
$('#img2').removeClass();
$('#img2').addClass('imgclass1');
})
})
![]() |
![]() |
![]() |
![]() |
----层次选择器--------
.imgclass
{
width: 100px;
height: 100px;
}
div
{
width: 250px;
height: 250px;
background-color: #eee;
border: solid 2px Blue;
}
$(function () {
$('#Button1').click(function () {
//$('#divFirst img').hide(2000); //获取的是id为divfirst的层中的所有tagname为img的元素,不管这些元素是否还嵌套在别的元素中
//$('#divFirst span img').hide(2000); //获取的是id为divfirst的层中的所有sp