2011-11-28 79 views
0

外讀取輸入我有一個簡單的表格一樣最簡單的方法爲FORM

<form method="post" action="target.php"> 
<input class="button" type="submit" value="Submit" /> 
</form> 

我想讀atable複選框。因此,複選框輸入外<form>作爲

<input type="checkbox" name="tick[]" value="'.$value.'" /> 

什麼是最簡單的jQuery的行動來讀取檢查的值,並通過POST的形式給他們?

P.S.由於表格中的每一行都有表格,因此我無法將整個表格放在<form>標記內。

+0

是什麼你打算爲禁用JavaScript的用戶做些什麼? –

+0

首先,我想到了一個無javascript的方法,但我沒有找到一個實用的方法。你能爲此提出一個純粹的html方法嗎?這將是理想! – Googlebot

+0

你是什麼意思,通過JavaScript的閱讀價值的方法????? – mplungjan

回答

1

試試這個 - 我沒有測試它。

$("input[name^=tick]:checked").each(function() { 
    $(this).val() // this line should contain the value of each checked checkbox, you can use it as you want 
}); 
1

您可以通過使用jQuery serialize()serializeArray()方法獲取整個在一個單一的對象/數組:

alert($('#<idOfForm>').serialize()); // will alert all form values in key/value string 

或使用$.post()提交表單:

$.post("target.php", $("#<idOfForm>").serialize());