jQuery属性操作

(1)
添加属性:
$("div").attr("属性",111);
获取属性值
$("div").attr("属性");
移除属性:
$("div").removeAttr("属性");
一些特殊属性需要用prop来修改
(2)
获取标签的value
$("div").val();
给标签赋值
$("div").val("啊大大");
获取双标签的文本:
$("div").text();//不识别内容标签
$("div").html();//识别内容标签
(3)
尺寸操作:
获取内容高度:
$("box").height();
设置高度
$("box").height("200px");
(4)
坐标值操作:只读
offset.top();//和offset不一样。距离整个页面的顶部的距离
position.top();//距离父元素带有定位的距离
scrollTop();//滚动条的距离
(5)
事件绑定:不会重叠,可以绑定多个相同的事件
$("div").click(function(){});
$("div").bind("事件1 事件2",function(){});
$("div").delegate("绑定对象","事件1 事件2",function(){});
$("div").on("事件1 事件2","事件源",{"name":111},fuction(event){
event(event.data.name);
});
解除事件绑定:
$("div").unbind("事件","事件源");
$("div").off("事件","事件源");
(6)
触发事件:
$("div").click();
$("div").trigger("click");
//触发浏览器行为
$("div").triggerHandler("click");
//不触发浏览器行为

posted @ 2017-02-14 10:16  赵小妖  阅读(114)  评论(0编辑  收藏  举报