【内部插入】
.append(content1, [contentN]) --- content为string/jq/DOM,如果为jq/DOM则进行移动操作
.append( jq.clone(true), '<div>test</div>' )
.append(function(i, html){return content})
.prepend(同上两)
.appendTo(selector) --- 移动
.prependTo(selector)
【外部插入】
.after(content1, [contentN])
.after( jq.clone(true), '<div>test</div>' )
.after(function(i, html){return content})
.before(同上两)
.insetAfter(selector) --- 移动
.insetBefore(selector)
【包裹】
.wrap(tabNames|selector) --- '<div></div>':div 、 '<div><p></p></div>':div>p 、 '<div> <p></p></div>':div
.wrap(function(i){return tabNames|selector})
.unwrap() --- 移除父标签
.wrapAll(tabNames|selector) --- 将所有匹配元素移动到第一个匹配元素的位置,然后 ...
.wrapInner(tabNames|selector) --- 与wrap()相反
.wrapInner(function(i){return tabNames|selector})
【替换】
$a.replaceWith(htmlStr|selector) --- $a被替换,返回被替换前的jq,并且htmlStr|selector被移动
$a.replaceWith(function(i, html){return htmlStr|selector}) --- html为innerHTML
htmlStr|selector.replaceAll(selector) --- selector被替换,返回被替换后的jq,并且htmlStr|selector被移动
【删除】
.empty() --- 清空内部所有
.remove(selector) --- 移除(包括data/事件)
.detach(selector) --- 移除(不包括data/事件)
【复制】
.clone(false, [false]) --- (元素本身,元素的子孙)
.clone() --- false false
.clone(true) --- true true
.clone(true, false) --- true false
【属性】
表单元素的type不建议修改,表单元素建议用prop
//节点属性
.attr(key) --- 访问eq(0)
.attr(key, val|function(i, currentVal){ return val }) 、 .attr(obj) --- 设置
.removeAttr(keys)
//DOM属性
.prop(key) --- 访问eq(0)
.prop(key, val|function(i, currentVal){ return val }) 、 .prop(obj) --- 设置
.removeProp(keys)
【属性class】
.addClass(classes|function(i, currentClassName){ return classes })
.removeClass(classes|function(i, currentClassName){ return classes })
.toggleClass(classes|function(i, currentClassName){ return classes })
【HTML】
.html() --- 访问eq(0)
.html(htmlStr|function(i, currentHtml){ return htmlStr }) ) --- 设置
.text() --- 访问eq(0)
.text(text|function(i, currentText){ return text }) ) --- 设置
.val() --- 访问eq(0)
.val(val|function(i, currentVal){ return val }) ) --- 设置
【CSS】
多个单词优先使用驼峰命名:marginTop
.css(name) --- 访问eq(0)
.css([name1, name2, nameN]) --- 访问eq(0),参数为数组
.css(name, val|function(i, currentVal){ return val })) --- 设置,如果val为空则清除
.css(obj) --- 设置
$.cssHooks --- css钩子:设置或获取特定CSS属性时的方法(同名覆盖)
【位置】
//相对于document的坐标,只对可见元素有效
.offset() --- 访问eq(0)
.offset(obj|function(i, currentObj){ return obj })) --- 设置(基于相对定位来达到目的地)
//相对于被定位的祖辈元素的坐标,只对可见元素有效
.position() --- 访问eq(0)
.scrollTop() 、 .scrollLeft() --- 访问eq(0)
.scrollTop(val) 、 .scrollLeft(val) --- 设置
【尺寸】
//content
.height() --- 访问eq(0)
.height(height|function(i, currentHeight){ return height }) --- 设置
//content + padding
.innerHeight() --- 访问eq(0)
.innerHeight(function(i, currentInnerHeight){ return height }) --- 设置
//content + padding + border |+ margin
.outerHeight(空|true) --- 访问eq(0)
【效果】
.show()
.hide()
.toggle()
......