@addClass( class )
// 在節點裡加入class = "selected"
// 移除 : removeClass( class ).
$("p").addClass("selected")

@attr( name )
// 取得<img src="test" alt="" /> 裡的src值
// before : <img src="test.jpg" alt="" />
// Result :  test.jpg
$("img").attr("src");
 
@attr( properties )
// 將<img alt="" />  加入 src="test.jpg" alt="Test Image"
// before : <img alt="" />
// Result :  <img src="test.jpg" alt="Test Image" />
$("img").attr({ src: "test.jpg", alt: "Test Image" });
 
@attr( key, value )
// 指定物件 的 key 並 設定 value
// 將 <img alt="" /> 加入 src = "test.jpg"
// before : <img alt="" />
// Result :  <img src="test.jpg" alt="" />
$("img").attr("src","test.jpg");
// 將
<input /> 加入 value = "test.jpg"
// before :
<input />
// Result :
<input value="test.jpg" />
$("input").attr("value","test.jpg");
 
@attr( key, fn )
// 在<img alt="" />裡加入 title
//title 值 則是用function 回傳
//Before: <img src="test.jpg" alt="" />
//Result: <img title="test.jpg" src="test.jpg" alt="" />
$("img").attr("title", function() { return this.src });
//Before : <img title="pic" alt="" /><img title="pic" alt="" /><img title="pic" alt="" />
//Result: <img title="pic1" alt="" /><img title="pic2" alt="" /><img title="pic3" alt="" />
$("img").attr("title", function(index) { return this.title + (++index); });
 
@html()
// 取得
<div> xxx</div>
xxx <= 取得的東西
// Before :
<div> xxx</div>
// Result : xxx
$("div").html()
 
@html( val )
// 改變
<div>xxx</div>
為
<div><strong>new stuff</strong></div>
// Before :
<div> xxx</div>
// Result :
<div><strong>new stuff</strong></div>
$("div").html("<strong>new stuff</strong>");
 
@removeAttr( name )
//移除
<input disabled="disabled" />
// Before :
<input disabled="disabled" />
// Result :
<input />
$("input").removeAttr("disabled")
 
@removeClass( class )
//移除裡的 class
// Before :
Hello
// Result :
Hello
 
$("p").removeClass()
// Before :
Hello
// Result :
Hello
 
$("p").removeClass("selected")
// Before :
Hello
// Result :
Hello
 
$("p").removeClass("selected highlight")
 
@text()
//取得裡的字串
// Before :
<strong>Test</strong> Paragraph.
Paraparagraph
 
// Result : Test Paragraph.Paraparagraph
$("p").text();
 
@text( val )
//取代內的字串
// Before :Test Paragraph.
 
// Result :
<strong>Some</strong> new text.
 
$("p").text("<strong>Some</strong> new text.");
// Before :
Test Paragraph.
// Result :
<strong>Some</strong> new text.
 
$("p").text("<strong>Some</strong> new text.", true);
 
@toggleClass( class )
// 將有 移除 , 如果沒有 則加入
// Before :
Hello
Hello Again
// Result :
Hello,Hello Again
 
$("p").toggleClass("selected")
 
@val()
// 抓取 INPUT 的 VALUE值
// Before :
<input type="text" value="some text" />
// Result :  "some text"
$("input").val();
 
@val( val )
// 將INPUT 的 VALUE 值 改變為指定
// Before :
<input type="text" value="some text" />
// Result :
<input type="text" value="test" />
$("input").val("test");
原文出處: http://blog.shian.tw/jquery-attributes.html 

arrow
arrow
    全站熱搜

    Frank 發表在 痞客邦 留言(0) 人氣()