0

我有一个四列的表格,每行末尾都有一个复选框。我想知道是否有一种编写 jquery 函数的方法,该函数将在选中复选框并单击提交按钮时选择每行的所有值..然后将值传递给 .php 文件处理/显示。我想使用 .php 文件的原因是因为我想运行一个查询来显示我系统上的所有注册用户,然后将检查的行(id 和 name)发送给这些用户。

听起来很复杂,但我真的需要一些帮助。提前致谢。

这是html代码:

<div class="valuesOfObs">
<table>
<thead><tr><th>Valuation Name</th><th>Valuation Goal</th><th>Valuation Description</th><th>Options</th><th>Invite</th></tr></thead>

<tbody>
<?php
$sql = 'SELECT * FROM valuation';
$results = $db->query($sql);
$rows = $results->fetchAll();

foreach ($rows as $row) {
echo '<tr id="'.$row['ValuationID'].'">';
echo '<td class="crsDesc">'.$row['ValuationName'].'</td>
<td >'.$row['ValuationGoal'].'</td> 
<td >'.$row['ValuationDescription'].'</td>
<td ><a href =values.php?action=invite&id=aValue> xValue </a></td>
<td > <input type="checkbox" name="selectValue">
</td>';
echo '</tr>';
}?>
</tbody>
</table>
</div>
<input type="button" name="addrow" id="addrow" value="Add row">
<input type="button" name="inviteObs"    id="inviteObs" value="Invite Obstacle";>

到目前为止,这是我为 jquery 编写的内容。我试图泄露这些值,以便我可以具体选择要处理的值,然后再使用 .join() 方法。如果走错路请帮忙

$("input[type=checkbox], input[type=button]").on("click", function () {
$( ":checked" ).map(function() { 
return $(this).closest("tr").text();
}).split("</td><td>");

var compName = $("#id").val();

$.ajax({
url : "inviteObstacles.php",
type : "POST",
data : {"compID" : compName},
success : function (n){
//do something
}
})

});
4

1 回答 1

1

Use .map() function to pass each element in the current matched set through a function, which will produce new jQuery object containing the return values.

Here is a code:

$("input[type=checkbox]").on("click", function () {
$( ":checked" ).map(function() { return $(this).closest("tr").text();
}).get().join();   //Use join to split the fetched row using separator "," on server-side
});

Demo: http://jsfiddle.net/tSeau/1/

于 2013-11-05T05:24:42.797 回答