Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击并提交表单时禁用表或提交按钮_Javascript_Html_Hide_Html Table - Fatal编程技术网

Javascript 单击并提交表单时禁用表或提交按钮

Javascript 单击并提交表单时禁用表或提交按钮,javascript,html,hide,html-table,Javascript,Html,Hide,Html Table,我正在用BD上的查询创建一个动态表,问题是我想在每次提交时禁用表上的一个按钮, 我希望在不加载页面的情况下提交表单,以便禁用按钮可见 <?php $theCounter=0; while($row = mysql_fetch_object($result)) { ?> <form id="id" action="table.php" method="post"&g

我正在用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++;
            }

        ?>

PHP:-


如果希望在第一次提交后在所有页面加载上禁用该按钮,则需要在会话中存储一些标志,以指示该按钮已被单击。你需要在每次页面加载时检查该标志。

我不确定我是否理解了你想要实现的一切,但以下是我对你的问题的理解:

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

document.forms[0]。onsubmit=函数(e){
e、 preventDefault();//开始时,阻止脚本重新加载页面
var form=e.currentTarget;//获取表单
form.push_check.disabled=true;//设置提交按钮已禁用
if(form.idUser.value){//如果有数据要发送,则发送数据
document.forms[0]。onsubmit=null;//将事件侦听器设置为null,否则onsubmit是一个永久循环
document.forms[0].submit();//最后将数据发送到php脚本
}
否则{
form.mysubmit.disabled=false;//没有要发送的数据
}
}

您可以将这个小脚本放在body标记之后或之内。它应该在每个浏览器中都能工作。

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


表单之间的字段。。。。。

您好,我通过以下方式实现:

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


因为我已经对我的数据库进行了查询,并且按钮正在进行更改,我正在检查是否已经进行了更改,如果没有,我将显示按钮!非常感谢您的评论

给那个按钮分配一个id,然后通过javascript禁用它怎么样?是的,我已经试过了,但问题是每次我按下按钮,页面刷新,它又被创建了!对不起,我说的是英语。你不能通过提交这样的表格来达到你想要达到的目的。如果你不想重新加载页面,你必须通过ajax提交表单。要求是(或者我理解的是)按钮在点击后重新加载页面时应被禁用/不可见。是的,正如Darshan所说,我会尝试添加“动态”id与$TheCounter一起指向我的按钮如果你想让它不可见,请使用css样式的可见性。你想让脚本使用动态id吗?我想上面的脚本就是你想要的。如果它有效,请给我的答案投赞成票。
<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>
<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>
<?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
                        }
                        ?>