我想从已检查过复选框的HTML表格行中获取数据。
Here's my table. It has some hidden fields as well.
目前,我能够获取数据,但它采用以下格式:
QueryResult result = twitter.search(query);
for (Status status : result.getTweets()) {
String json = DataObjectFactory.getRawJSON(status);
}
来自多行的数据使用逗号连接在一起,但我需要将来自不同行的数据分开,如下所示:
function submit() {
var postData = $("#passwd").serialize();
//alert(postData);
$.ajax({
type: "POST",
url: "http://www.redcraft.it/submit.php",
data: postData,
success: function(redirect) {
location.href(redirect);
}/*,
error: function() {
alert('Failure');
}*/
});
}
因为我需要将它插入MySQL表中。
这是我的表格代码:
SelectedData = ('Samanyou Garg', '2841', '19661', '8110', '2017-04-05',
'Scientific Computing', 'null', 'M', '0', 'null', 'asdasd', 'undefined',
'11581', 'Test UK', '2861', '7458', '8110', '2017-07-13', 'Scientific
Computing', 'null', 'M', '0', 'null', 'gdfg', 'undefined', '11581')
以下是在我的表格中获取数据的代码:
('Samanyou Garg', '2841', '19661', '8110', '2017-04-05', 'Scientific
Computing', 'null', 'M', '0', 'null', 'asdasd', 'undefined', '11581'),
('Test UK', '2861', '7458', '8110', '2017-07-13', 'Scientific Computing',
'null', 'M', '0', 'null', 'gdfg', 'undefined', '11581')
这是我目前的javascript代码 -
<table class="table table-striped table-bordered table-list" data-page-length="100">
<thead>
<tr>
<!-- EVENTS TABLE ROW -->
<th><input type="checkbox" onClick="check(this)" id="selectall" /></th>
<th class="align_center">Donor Name</th>
<th class="align_center">Donor Department</th>
<th class="align_center">Last Donation Date</th>
</tr>
</thead>
<tbody id="allDonors">
</tbody>
</table>
请建议如何做到这一点。
答案 0 :(得分:0)
function myfunc() {
var valueList = [];
$('#allDonors tr').each(function() {
$(this).find("input[name='bar']:checked").each(function() {
var values = [];
$(this).closest("td").siblings("td").each(function() {
values.push($(this).text());
});
valueList.push(values.join(", "));
});
});
console.log("(" + valueList.join("),(") + ")");
}
$("#addDonor").click(function() {
myfunc();
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-striped table-bordered table-list" data-page-length="100">
<thead>
</thead>
<tbody id="allDonors">
<tr>
<td>
<input type="checkbox" name="bar" /> </td>
<td class="align_center">Donor Name</td>
<td class="align_center">Donor Department</td>
<td class="align_center">Last Donation Date</td>
</tr>
<tr>
<td>
<input type="checkbox" name="bar" /> </td>
<td class="align_center">Donor Name</td>
<td class="align_center">Donor Department</td>
<td class="align_center">Last Donation Date</td>
</tr>
</tbody>
<input type="submit" value="Add Donar" id="addDonor" />
</table>
&#13;
这是你在找什么?为简单起见,我已删除了ajax调用。