###课程回顾
- $(function(){ })
- $("#abc").click(function(){})
- 选择器
- 基础选择器 标签名 id class 分组,任意元素
- 层级选择器 div span ,div>span, div+span,div~span ,siblings(),prev(),prevAll(),next(),nextAll()
- 过滤选择器 div:first div:last , div:even div:odd, div:lt(n) div:gt(n) div:eq(n) ,div:not(.one)
- 内容选择器 div:has§ div:empty div:parent div:contains(‘xxx’)
- 可见选择器 div:hidden div:visible , show() hide() toggle()
- 属性选择器 div[id] div[id=‘xxx’] div[id!=‘xxx’]
- 子元素选择器 div:nth-child(n) div:first-child div:last-child
- 表单选择器 :input :password :radio :checkbox :checked input:checked :selected
- js对象和jq对象互相转换
- js转jq var jq = $(js)
- jq转js var js = jq[0] jq.get(0)
- 创建元素对象 var xxx = $(" ")
- 添加元素 父元素.append(xxx)最后面 父元素.prepend(xxx)最前面
- 插入元素 兄弟元素.after(xxx) 兄弟元素.before(xxx)
- 删除元素 元素.remove()
- 样式 xxx.css(“color”,“red”) .css({"":"","":""})
- 属性 xxx.attr(“id”,“xxx”)
- 文本 xxx.text(“xxxx”)
- html xxx.html(“
xxx
”)
实现步骤:
- 导入jq框架 并创建一个新的script标签写代码
- 在页面加载完成事件里面给按钮动态绑定点击事件
- 在点击事件里面 创建三个td td的内容为三个文本框里面的内容,再创建一个tr,把三个td添加到tr里面
- 把创建好的tr添加到table里面,搞定!
###事件模拟
//模拟按钮的点击事件
$("input").trigger("click");
###hover()
-
格式 hover(fn1,fn2); 等效 onmouseover+onmouseout
//给所有div 添加移入移出事件 $("div").hover(function(){ $(this).css("color","blue"); },function(){ $(this).css("color","red"); })
###动画
if($(this).val()=="隐藏"){
$("img").hide(3000);
}else if($(this).val()=="显示"){
$("img").show(2000,function(){
$("img").hide(2000,function(){
$("img").show(1000);
});
});
}else if($(this).val()=="上滑"){
$("img").slideUp(3000);
}else if($(this).val()=="下滑"){
$("img").slideDown(3000);
}else if($(this).val()=="淡出"){
$("img").fadeOut(3000);
}else if($(this).val()=="淡入"){
$("img").fadeIn(3000);
}else{
$("img").animate({"left":"250px"},1000)
.animate({"top":"250px"},1000)
.animate({"left":"0"},1000)
.animate({"top":"0"},1000)
.animate({"width":"400px","height":"300px"},1000)
.animate({"width":"200px","height":"150px"},1000);
}
###下雪练习