我在BD上创建一个带有查询的动态表,问题是我每次提交时都要禁用表上的按钮, 我希望在没有页面加载的情况下提交表单,以便可以看到禁用的按钮。
<?php
$theCounter=0;
while($row = mysql_fetch_object($result))
{
?>
<form id="id" action="table.php" method="post">
<input type="hidden" value="<?php echo $row->id_table; ?>" name="idUser">
<tr>
<td><?php echo $row->id_userS; ?></td>
<td><?php echo $row->username_s; ?></td>
<td><?php echo $row->num_people; ?></td>
<td><?php echo $row->start_time; ?></td>
<td>
<input type="submit" name="delete_check" value="Eliminar">
</td>
<td>
<input type="submit" name="push_check" value="Enviar Push">
</td>
</form>
<?php
$theCounter++;
}
?>
我要禁用或隐藏名为“push_check”的按钮。 如果我禁用按钮或隐藏按钮
并不重要提前致谢!
答案 0 :(得分:0)
PHP: -
<?php
$theCounter=0;
while($row = mysql_fetch_object($result))
{
Echo "
<form id='id' action='table.php' method='post'>
<input type='hidden' value='$row->id_table;' name='idUser'>
<tr>
<td>$row->id_userS</td>
<td>$row->username_s</td>
<td>$row->num_people</td>
<td>$row->start_time</td>
<td>
<input type='submit' id='del$thecounter' name='delete_check' value='Eliminar' onclick='hide(del$thecounter)'>
</td>
<td>
<input type='submit' id='push$thecounter' name='push_check' value='Enviar Push' onclick='hide(push$thecounter)'>
</td>
</form>
";
$theCounter++;
}
?>
现在使用Javascript: -
function hide(a)
{
document.getElementById(a).style.visibility="hidden";
}
答案 1 :(得分:0)
如果您希望在第一次提交后在所有页面加载时禁用该按钮,则需要在会话中存储一些标记,该标记将指示该按钮已被单击。并且您需要在每个页面加载时检查该标志。
答案 2 :(得分:0)
我不确定我是否理解了你想要实现的一切,但这是我从你的问题中得到的:
<script>
document.forms[0].onsubmit = function(e){
e.preventDefault(); // at the beginning stop page from being reloaded by the script
var form = e.currentTarget; // get form
form.push_check.disabled = true; // set submit-button disabled
if(form.idUser.value){ // send data if there is data to send
document.forms[0].onsubmit = null; // set event listener null otherwise onsubmit is a forever-loop
document.forms[0].submit(); // send finally data to the php-script
}
else{
form.mysubmit.disabled = false; // there was no data to send
}
}
</script>
您可以将此小脚本放在body标签之后或之内。它应该适用于每个浏览器。
答案 3 :(得分:0)
另一种阻止加载页面的方法是使用 目标
<form action='' method='POST' target='upload_target' onsubmit='hide(dynamicid)'>
fields between form.....
<input type='submit' id='dynamicid'/>
<iframe id='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px solid #fff;'></iframe>
</form>
答案 4 :(得分:0)
嗨我设法做到了这一点:
<?php
$push_button = $row->time_push;
if($push_button==0)
{
?>
<td>
<input type="submit" id='push$thecounter' name="push_check" value="Enviar Push">
</td>
<?php
}
?>
由于我已经对我的数据库进行了查询,并且按钮正在进行更改,我正在检查是否已经进行了更改,如果没有,则显示按钮!非常感谢您的所有评论!