var student = $('#student tr').find('td').find('input[type=\"text\"]');
student.each(function(index, element) {
var label = $(element).parent().find('span').text();
var member = $('#student').attr('name');
studentnames.push({
value: $(element).val(),
label: label,
member: member
});
});
這就是我如何製作我的數組。這是輸出array push change格式jquery
[{
"value": "jackie",
"label": "First Name",
"member": "science club"
}, {
"value": "chan",
"label": "Middle Name",
"member": "science club"
}, {
"value": "lee",
"label": "Last Name",
"member": "science club"
}, {
"value": "jr",
"label": "Suffix",
"member": "science club"
}, {
"value": "Tokyo",
"label": "City/Province",
"member": "science club"
}, {
"value": "Nanporo",
"label": "Town/Municipality",
"member": "science club"
}, {
"value": "Sorachi",
"label": "District",
"member": "science club"
}, {
"value": "1234",
"label": "Contact Number",
"member": "science club"
}]
我怎樣才能改變它像
[{
"First Name": "jackie",
"Middle Name": "chan",
"Last Name": "lee",
"Suffix": "jr",
"City/Province": "Tokyo",
"Town/Municipality": "Nanporo",
"District": "Sorachi",
"member": "science club"
}]
我的HTML表是這樣的
<table id="student" name="student" class="student">
<tr>
<td>
<center>
<input type="text" name="fname" class="fname" />
<br> <span><small><i>First Name</i></small></span> </center>
</td>
<td>
<center>
<input type="text" name="mname" class="mname" />
<br> <span><small><i>Middle Name</i></small></span> </center>
</td>
<td>
<center>
<input type="text" name="lname" class="lname" />
<br> <span><small><i>Last Name</i></small></span> </center>
</td>
</tr>
<tr>
<td>
<center>
<input type="text" name="suffix" class="suffix" />
<br> <span><small><i>Suffix</i></small></span> </center>
</td>
</tr>
<tr>
<td>
<center>
<input type="text" name="city" class="city" />
<br> <span><small><i>City/Province</i></small></span> </center>
</td>
<td>
<center>
<input type="text" name="town" class="town" />
<br> <span><small><i>Town/Municipality</i></small></span> </center>
</td>
<td>
<center>
<input type="text" name="district" class="district" />
<br> <span><small><i>District</i></small></span> </center>
</td>
</tr>
<tr>
<td>
<center>
<input type="text" name="contact" class="contact" />
<br> <span><small><i>Contact Number</i></small></span> </center>
</td>
</tr>
<tr>
<td>
<input type="button" id="addtable" value="Add" name="" /> </td>
<td>
<input type="button" id="removetable" value="Remove" name="" /> </td>
</tr>
</table>
按鈕中添加或刪除格式有一個jquery功能添加相同的表格或刪除取決於用戶點擊
你能提出什麼其他的標籤我可以使用'TD tag' – guradio