jQuery¼¼Êõ

jQuery°ïÖúÖ®AjaxÆäËü£¨Èý£©serializeArray()

×ÖºÅ+ ×÷Õߣºjamie À´Ô´£º 2014-11-16 22:49 ÎÒÒªÆÀÂÛ( )

serialize()Õâ¸öº¯ÊýÊÇAjaxÏÂÐòÁбí±í¸ñµÄÒ»¸öÏà¹Øº¯Êý£¬»¹ ÓÐÒ»¸öÀàËÆÕâ¸öº¯ÊýµÄÐòÁл¯±í¸ñÔªËØserializeArray()serializeArray()Ðò Áл¯±í¸ñÔªËØ (ÀàËÆ

serialize()Õâ¸öº¯ÊýÊÇAjaxÏÂÐòÁбí±í¸ñµÄÒ»¸öÏà¹Øº¯Êý£¬»¹ ÓÐÒ»¸öÀàËÆÕâ¸öº¯ÊýµÄÐòÁл¯±í¸ñÔªËØserializeArray()

serializeArray()

Ðò Áл¯±í¸ñÔªËØ (ÀàËÆ '.serialize()' ·½·¨) ·µ»Ø JSON Êý¾Ý½á¹¹Êý¾Ý¡£

·µ»ØÖµ£ºjQuery

ʾ Àý£º
È¡µÃ±íµ¥ÄÚÈݲ¢²åÈëµ½ÍøÒ³ÖС£
HTML ´úÂë:
  <p id="results"><b>Results:</b> </p>
<form>
<select name="single">
<option>Single</option>
<option>Single2</option>
</select>
<select name="multiple" multiple="multiple">
<option selected="selected">Multiple</option>
<option>Multiple2</option>
<option selected="selected">Multiple3</option>
</select><br/>
<input type="checkbox" name="check" value="check1"/> check1
<input type="checkbox" name="check" value="check2"
checked="checked"/> check2
<input type="radio" name="radio" value="radio1"
checked="checked"/> radio1
<input type="radio" name="radio" value="radio2"/> radio2
</form>

jQuery ´úÂë:
  var fields = $("select, :radio").serializeArray();
jQuery.each( fields, function(i, field){
$("#results").append(field.value + " ");
});

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
ÍøÓѵãÆÀ
±