这是我第二次在这里寻求帮助,所以我希望你不介意我犯了错误。
请参阅我在访问元素时遇到问题(在本例中,这是一个
这是JQuery:
$("#tblAddServices tbody").delegate("tr", "click", function(){
firstCellServ = $("td:first", this).text();
secondCellServ = $("td:eq(1)", this).text();
thirdCellServ = $("td:eq(2)", this).text();
fourthCellServ = $("td:eq(3)", this).text();
})
$('.service').on('click', function(e){
var $table = $("#tblServiceIncluded");
var newTR = $("<tr><td colspan='"3'" name='"servID[]'">"+firstCellServ+"</td>
<td colspan='"3'">"+secondCellServ+"</td>
<td colspan='"3'">"+thirdCellServ+"</td>
<td colspan='"2'" class='"sumService'">"+fourthCellServ+"</td>
</tr>");
$table.append(newTR);
});
现在,我有一个PHP脚本,它应该获取我命名为"servID[]"的表第一列的值。我正在使用数组来获取其值,但我总是以"servID"的未定义索引警告结束。
这是 PHP 脚本:
<?php
if(isset($_POST['btnSavePack']))
{
$serviceArray = array();
foreach($_POST['servID'] as $serviceKey){
$serviceArray[] = $serviceKey;
}
foreach($serviceArray as $result) {
echo $result, '<br>';
}
}
?>
我希望你能帮我想办法让这项工作。我知道我可以用Ajax做到这一点,但我更喜欢这种方法,因为我只是一个初学者。 谢谢。
您可以将值放在隐藏类型的输入框中。
"<td colspan='"3'"><input name='"servID[]'" type='"hidden'" value='""+firstCellServ+"'"/>"+firstCellServ+"</td>"