javascript - 计时器在 php 文件上使用 js 使输入和文本区域样式返回为默认值

标签 javascript php html css mysql

提交后我在 php 文件中的 js 上使用计时器将数据插入 mysql 数据库问题是当我按下提交文本区域的样式和输入更改并返回到默认值时,因为计时器

我尝试在没有计时器的情况下提交结果很好并且没有任何样式改变所以问题在于使用计时器功能

com.php

<?php
require('connection.php');

$status = '';
$text = '';
$com = '';
$url = 'index.php';

function timer($url){
    echo' <script>
    setTimeout(function () {
      window.location.href= "'.$url.'";   
       },3000); 
     </script>';

}

if(isset($_POST['addCom'])){
            $com= mysqli_real_escape_string($db,$_REQUEST['com']);
            $text= mysqli_real_escape_string($db,$_REQUEST['text']);
            $stmt = $db->prepare("insert into testcomments (com,text) values (?,?)");
            $stmt->bind_param('ss',$com,$text);
            $stmt->execute();
            $status = "Done ";
            $com= '';
            timer($url);
}
?>

<!doctype html>
<html >
<head>

<link rel="stylesheet" href="style/registeration1.css">

</head>

<body>

    <form method="post"  enctype="multipart/form-data">
        <div class="input-group">
            <textarea name="com" > </textarea>
        </div>
        <div class="input-group">
            <input type="text" name="text" > 
        </div>
        <div class="input-group">
            <button type="submit" class="btn" name="addCom" id="add" >اضافه</button>
        </div>
        <p style="color:#FF0000;"><?php echo $status; ?></p>
    </form>

</body>
</html>

registeration1.css


form {
    width: 30%;
    margin: 0px auto;
    padding: 20px;
    border: 1px solid #B0C4DE;
    background: white;
    border-radius: 0px 0px 10px 10px;
}
.input-group {
    margin: 10px 0px 10px 0px;
}

.input-group input  {
    height: 30px;
    width: 93%;
    padding: 5px 10px;
    font-size: 16px;
    border-radius: 5px;
    border: 1px solid gray;
}
.btn {
    padding: 15px;
    padding-left:30px;
    padding-right:30px;  
    font-size: 18px;
    color: white;
    background: black;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}



.input-group textarea{
    height: 30px;
    width: 93%;
    padding: 5px 10px;
    font-size: 16px;
    border-radius: 5px;
    border: 1px solid gray;
}

我希望使用定时器后样式不会改变,但实际输出是 input 标签和 textarea 标签的样式已经改变

最佳答案

用这个替换你的 php 部分:

<?php
require('connection.php');

$status = '';
$text = '';
$com = '';
$url = 'index.php';

function timer($url){
    sleep(3);
    header('Location: ' . $url); 
}

if(isset($_POST['addCom'])) {
    $com=  mysqli_real_escape_string($db,$_REQUEST['com']);
    $text = mysqli_real_escape_string($db,$_REQUEST['text']);
    $stmt = $db->prepare("insert into testcomments (com,text) values (?,?)");
    $stmt->bind_param('ss',$com,$text);
    $stmt->execute();
    $status = "Done ";
    $com= '';
    timer($url);
}
?>

关于javascript - 计时器在 php 文件上使用 js 使输入和文本区域样式返回为默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56284872/

相关文章:

javascript - 如何将点击绑定(bind)到父级没有类的元素?

javascript - 使用 javascript 和 jquery 将图像添加到 svg 文件

javascript - 无法在 PHP 中读取 csv 并将其传递给 html 文件中的 javascript

php - Sum 在 php mongodb 中不起作用

html - 如何使用CSS自动调整div中图像的大小?

javascript - 如何创建在弹出窗口下使用的覆盖层

javascript - 当我尝试将某个值添加到总和中时,函数会继续渲染。创建 react 应用程序

javascript - Alfresco Share 客户端同步表单验证

php - 如何在Elasticsearch PHP中执行前缀查询?

html - Angular 4提交表单后清空输入框