以往使用ajax傳值給php時,都需要將每一個 input 的值抓出來寫成 'xxx=xxx&xxx=xxx', 現在jQuery 的 serialize 可以很簡單的達成,以下使用例子說明

<input type='text' name='shian' id='shian' value='shian'/>

<input type='text' name='john' id='john' value='John'/>

<input type='text' name='boston' id='boston' value='Boston'/>

 

使用:

利用jQuery的serialize來取得所有 input的type='text'值

$("input[@type=text]").serialize();

 

結果:

shian=shian&john=john&boston=Bostonn

Posted by shian0745 at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(416)