0

我在我的 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”。我禁用按钮或隐藏按钮都没有关系

提前致谢!

4

5 回答 5

0

Hi i manage to do it by this:

<?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
                        }
                        ?>

Since i've already making a query to my DB, and the button is making a change, im checking if that change its already made, so if not, im displaying the button! thanks a lot for all your comments!

于 2013-06-13T15:03:57.720 回答
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";
}
于 2013-06-12T18:16:07.060 回答
0

如果您希望在第一次提交后在所有页面加载时禁用该按钮,那么您需要在会话中存储一些标志,表明该按钮已被单击。您需要在每次页面加载时检查该标志。

于 2013-06-12T18:19:30.610 回答
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-tag 之后或之内。它应该适用于每个浏览器。

于 2013-06-12T18:56:35.057 回答
0

防止加载页面的另一种方法是使用target

<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>
于 2013-06-12T19:01:49.140 回答