jQuery入门学习(1)---jQuery控制页面
1. 标记的属性
var sTitle=$("em:eq(0)").attr("title");- 获取属性的值
$("span").text(sTitle); - 设置属性的值
2. 元素的样式
$("span").addClass("Myclass");- 添加CSS类
$("span").click(function(){
$(this).toggleClass("Myclass");- 动态切换
}
);
3. 页面的元素
var text=$("p:first").text();- 直接获取、编辑内容
$("p:last").html(text);
$("img:eq(0)").clone().appendTo($("p"));- 克隆元素
$("img:eq(1)").clone().appendTo($("p:eq(1)"));
4. jQuery处理事件
$("img:eq(0)")
.bind("click",fun1=function(){$("#show").append("<div>你点我了1</div>")})- 事件监听
.bind("click",function(){$("#show").append("<div>你点我了2</div>")})
.bind("click",function(){$("#show").append("<div>你点我了3</div>")})
;
$("input[type=button]").click(function(){
$("img").unbind("click",fun1) - 移除事件监听
});
5. 表格隔行变色
$("table tr:nth-child(odd)").addClass("tabletr");

浙公网安备 33010602011771号