jQuery学习笔记(3)

4月 3, 2008 – 10:57 下午

本记: 13—-20点

13 removeAttr(name) 删除属性

eg: <input disabled=”disabled”/>

$(”input”).removeAttr(”disabled”)=><input/>

14 removeClass(class) 删除样式,当class是空时删除所有的样式,如果class为指定样式则删      指定样式

eg: <p class=”highlight selected first”>Hello</p>

$(”p”).removeClass(”selected highlight”)=>[ <p class=”first”>Hello</p> ]

$(”p”).removeClass() =>[ <p>Hello</p> ]

15. text() 取得element中的内容text(val) 设置element内容text与html差不多,只是text会把<,>用html标识符替换

eg: <p><b>Test</b> Paragraph.</p><p>Paraparagraph</p>

$(”p”).text() =>Test Paragraph.Paraparagraph;

<p>Test Paragraph.</p>

$(”p”).text(”<b>Some</b> new text.”);==>

<p><b>Some</b> new text.</p>

$(”p”).text(”<b>Some</b> new text.”, true) ==>

<p>Some new text.</p>
16.toggleClass(class) 这是一个比较有用的方法,就是当element存在参数中的样式的时候
取消,如果不存在就设置此样式
eg:<p>Hello</p><p class="selected">Hello Again</p>
$("p").toggleClass("selected")==>
[ <p class="selected">Hello</p>, <p>Hello Again</p> ]
17 val() 取得第一个element的vlaue值 val(val) 设置属性的值
eg: <input type="text" value="some text"/>
$("input").val() == >"some text";
$("input").val("test")==><input type="text" value="test"/>;
18 after(content)给相关的element从后面插入节点
eg: <p>I would like to say: </p>
$("p").after("<b>Hello</b>")==><p>I would like to say: </p><b>Hello</b>
<b>Hello</b><p>I would like to say: </p>
$("p").after( $("b") )==><p>I would like to say: </p><b>Hello</b>;
21 before(content)与after相反是插入到前面
eg: <p>I would like to say: </p>
$("p").after("<b>Hello</b>")==>><b>Hello</b><p>I would like to say: </p
19 append(content) 与上面不同的是append是添加把content做为子element
eg: <p>I would like to say: </p>
$("p").append("<b>Hello</b>")=><p>I would like to say: <b>Hello</b></p>;
eg: <p>I would like to say: </p><b>Hello</b>
$("p").append( $("b") )==>;
<p>I would like to say: <b>Hello</b></p>
20 appendto(content)与append刚好相反
<p>I would like to say: </p><div id="foo"></div>
$("p").appendTo("#foo")==>
<div id="foo"><p>I would like to say: </p></div>;




Post a Comment