精做高難度防水抓漏/壁癌/油漆等工程
責任施工、合約保固!
搬家公司油漆工程,講究細部修整
防潮粉刷,免費估價!

首頁  •  j2h 論壇 • 程式設計討論     • 

[JQuery] 取值的一些方法

房東:小蝦米
發表時間:2011-11-22
[檢舉]


@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 )
// 將有 class="selected" 移除 , 如果沒有 class="selected" 則加入
// 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");




  • 贊助網站       

    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務
    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!



  •  共 0 人回應

    姓名:
    佈告內容: