我有这个代码:
<?php
$result = mysqli_query($con,"SELECT * FROM table");
while($row = mysqli_fetch_array($result)){
echo "<input type=\"checkbox\" id=\"$row[use_id]\" name=\"things[]\" value='$row[col_id]' >$row[col]<br>";
echo "<input placeholder=\"description\" type=\"text\" name=\"ans1\" class='$row[col_id]' id=\"answer1\" style='display:none;'>";
echo "<align='left'><input placeholder=\"source\" type=\"text\" name=\"ans2\" class='$row[use_id]' id=\"answer2\" style='display:none;'>";
}
?>
使用这个脚本:
<script>
$(document).ready(function(){
$("input[type=checkbox]").change(function(){
var divId = $(this).attr("id");
if ($(this).is(":checked")){
$("." + divId).show();
}
else{
$("." + divId).hide();
}
});
});
</script>
我想使用 ths 代码从 2 个文本框中获取数据:
$checkBox = $_POST['things'];
for($i=0; $i<sizeof($checkBox); $i++){
$qs = "INSERT INTO sccm_reherb.table2 values('$_POST[id]','".$checkBox[$i]."','$_POST[ans1]','$_POST[ans2]')";
echo $qs;
mysqli_query($con,$qs) or die(mysqli_error($con));
}
但 '$_POST[ans1]' 和 '$_POST[ans2]' 总是空的..谁能帮帮我?提前致谢!