1
我是jQuery中的初學者。我希望我所有的表單輸入值在數組中=(項目01,項目02和和)保存。保存數組中的輸入並顯示所有項目jquery javascript
它應該在表格中顯示項目?
我做了什麼,它不工作:
<form id="form_id">
<label for="firstname">First Name:</label>
<input type="text" id="firstname" name="name" value="" placeholder="Max" required="required" autofocus="autofocus" />
<label for="lastname">Last Name:</label>
<input type="text" id="lastname" name="name" value="" placeholder="Max" required="required" autofocus="autofocus" />
<input type="submit" value="submit" id="submit-button" />
</form>
<div id="table">
<h2>List of all person</h2>
<table class="footable">
<thead>
<tr>
<th data-class="expand"> First Name </th>
<th> Last Name </th>
</tr>
</thead>
<tbody>
<tr>
<td>e.g --> array[1].firstname</td>
<td>e.g --> array[1].lastname</td>
</tr>
</tbody>
</table>
</div>
的JavaScript代碼:
$(function() {
$('#submit-button').click(function() {
var formInputs = new Array();
//Get the form ID
var id = $(this).parent().attr('id');
$('#' + id + ' input').each(function() {
//Get the input value
var inputValue = $(this).val();
//Get the input id
var inputId = $(this).attr('id');
//Add them to the array
formInputs[inputId] = inputValue;
});
show....
});
});
該表單上沒有任何輸入,你能告訴我們實際的HTML(或者它的一部分,如果它非常大)嗎? –
對不起,我已更新它。 – Fawi
什麼不適用於它? –