1. 程式人生 > >input type="checkbox",選中或取消,將value存入隱藏域

input type="checkbox",選中或取消,將value存入隱藏域

<pre name="code" class="javascript">$(function(){
        //將需要提交的checkbox的value,拼成字串,放入隱藏域replyway
			$('input[type=checkbox]').change(function(){	
				$('#replyway').val($('input[type=checkbox]:checked').map(function(){return this.value}).get().join(','));
			});
      });

<input type="checkbox" name="replyway_tele" id="replyway_tele" value="0" checked/><label for="replyway_tele">電話回覆</label>   <input type="checkbox" name="replyway_email" id="replyway_email" value="1"/><label for="replyway_email">郵件回覆</label><input type="hidden" name="replyway" id="replyway" value="">