Javascript 提交按钮不在Chrome中工作,但在Firefox中工作
嗨,退出按钮在chrome中不起作用。它在Firefox中运行良好。但是,如果我按下F12并保持开发人员控制台打开,那么按钮就会工作。当我按enter键时,该按钮也起作用。我很困惑。这是我的密码 HTML代码:Javascript 提交按钮不在Chrome中工作,但在Firefox中工作,javascript,php,mysql,Javascript,Php,Mysql,嗨,退出按钮在chrome中不起作用。它在Firefox中运行良好。但是,如果我按下F12并保持开发人员控制台打开,那么按钮就会工作。当我按enter键时,该按钮也起作用。我很困惑。这是我的密码 HTML代码: <form name="logoutform" method="post" onsubmit="logoutConfirmation()" action="" > <input type="submit" value="Logout" id="logou
<form name="logoutform" method="post" onsubmit="logoutConfirmation()" action="" >
<input type="submit" value="Logout" id="logoutbutton" name="userlogout" ><br>
</form>
PHP代码:
if(isset($_POST['userlogout']))
{
setcookie('user_name', '');
setcookie('user_id', '');
session_destroy();
header("Location: index.php");
}
在表单中定义动作php文件,如
<form name="logoutform" method="post" onsubmit="logoutConfirmation()" action="yourfile.php" >
<input type="submit" value="Logout" id="logoutbutton" name="userlogout" ><br>
</form>
如果不设置操作。它没有提交
如果文件名为“test.php”,请尝试以下操作:
如果PHP脚本在同一个文件中,那么您甚至不需要
操作=“”
只要这样做:
<form name="logoutform" method="post" onsubmit="logoutConfirmation()">
<input type="submit" value="Logout" id="logoutbutton" name="userlogout" ><br>
</form>
我知道这篇文章很老了。但如果有人有同样的chrome问题并登陆这里。试试这些。我查看了多个论坛,但似乎没有任何效果。所以我从头开始,基本表单元素,尝试提交,然后一次添加一个元素
<form action="file" method="POST">
<input type="submit" value="Submit">
</form>
我的问题是在action属性中添加php代码。这导致提交按钮在chrome中无法工作
// Do not add php code in your action. This will not work.
<form action="file.php?pg=<?php echo $page; ?>" method="POST">
...
<input type="submit" value="Submit">
</form>
//不要在操作中添加php代码。这是行不通的。
包含类似myfile.php的动作标记在哪里?嗨,php函数在同一页中。它不在不同的页面上。别担心!然后使用这个文件名!你认为问题出在PHP函数上吗?正如我所提到的,使用tab键导航并按enter键可以正常工作。我认为问题在于action=”“
。要么你试图接受答案并试图纠正这一点,要么就是运气不好。如果你纠正了这一点,但它还没有工作,你可能会对此抱怨。嗨,PHP函数在同一个页面中。它不在另一页。
<form action="file" method="POST">
<input type="submit" value="Submit">
</form>
// Do not add php code in your action. This will not work.
<form action="file.php?pg=<?php echo $page; ?>" method="POST">
...
<input type="submit" value="Submit">
</form>
<form action="file.php" method="POST">
...
<input type="hidden" name="pg" value="<?php echo $pg?>">
<input type="submit" value="Submit">
</form>