用php-echo替换js而不刷新


replace js with php echo without refresh

情况是我已经写出了类似的代码

<input type="text" name="date"<?php if(empty($date)){echo 'id="date"';}else{echo 'value='.$date;} ?> readonly/>

整页编码

<?php
    session_start();
    if(isset($_SESSION['rec_id']))
    {
        $enginenumber = $_SESSION['engn'];
        $model = $_SESSION['mod'];
        $vinnumber = $_SESSION['vinn'];
        $date = $_SESSION['date'];
        $time = substr($_SESSION['time'],0,5);
        $bikeid = $_SESSION['bk_id'];
        $recid = $_SESSION['rec_id'];
    }
    else
    {
        $enginenumber = "";
        $model = "";
        $vinnumber = "";
        $date = "";
        $time = "";
    }
    $_SESSION['line'] = $_GET['line'];
    $linenumber = $_SESSION['line'];
    $_SESSION['station'] = $_GET['st'];
    include('../../php/dbconnectmssql.php');
?>
<html lang="en">
    <head>
        <title>TH Bike Assembly RFT Database</title>
        <meta charset="utf-8"/>
        <link rel="stylesheet" type="text/css" href="../../css/main.css"/>
        <link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
        <link rel="stylesheet" type="text/css" href="../../css/external.css"/>
        <link rel="stylesheet" type="text/css" href="../../css/formrecords.css"/>
        <link rel="stylesheet" type="text/css" href="../../css/inputtabconroll2c.css"/>
        <script type="text/javascript" src="../../js/date_time.js"></script>
        <script type="text/javascript" src="../../js/jsdialog.js"></script>
        <script type="text/javascript" src="../../js/validate.js">window.onload=function(){validateform();}</script>
        <script type="text/javascript">window.onload=function(){GetClock();setInterval(GetClock,1000);}</script>
    </head>
    <body>
        <div class="main rft">
            <h1>Right First Time Record Line <?php echo $linenumber; ?> Chassis</h1>
            <form name="stationrec" method="post" action="../php/stationrec.php">
                <table class="headform">
                    <tr>
                        <td>
                            <p>VinNumber</p>
                            <input type="text" name="vinnumber" value="<?php echo $vinnumber; ?>"
                            <?php if(!empty($vinnumber)){echo "readonly";} ?>/>
                        </td>
                        <td>
                            <p>Engine Number</p>
                            <input type="text" name="enginenumber" value="<?php echo $enginenumber; ?>"
                            <?php if(!empty($enginenumber)){echo "readonly";} ?>/>
                        </td>
                        <td>
                            <p>Model</p>
                            <input type="text" name="model" value="<?php echo $model; ?>"
                            <?php if(!empty($model)){echo "readonly";} ?>/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <p>Date</p>
                            <input type="text" name="date"
                            <?php if(empty($date)){echo 'id="date"';}else{echo 'value="'.$date.'"';} ?> readonly/>
                        </td>
                        <td>
                            <p>Time</p>
                            <input type="text" name="time"
                            <?php if(empty($date)){echo 'id="time"';}else{echo 'value="'.$time.'"';} ?> readonly/>
                        </td>
                        <td>
                            <input id="" class="myButton" type="submit" value="Bike-Pass/NewBike"/>
                        </td>
                    </tr>
                </table>
            </form>
            <div id="faultpanel" class="container">
                    <div class="">
                        <h2>Fault Records</h2>
                        <div class="tabbedcontain">
                            <ul class="col4">
                                <li id="fhlschs" onclick="scchs()">Chassis</li>
                                <li id="fhlsuk" onclick="scuk()">UK</li>
                            </ul>
                        </div>
                        <div class="ftlscon">
                            <div id="ftlschs" class="col8">
                                <table>
                                    <tr>
                                        <th>Main Problem</th>
                                        <th>Location</th>
                                        <th>FoundBy</th>
                                        <th>Chassis Number</th>
                                        <th>Station</th>
                                        <th>Damage Grade</th>
                                        <th>More Info</th>
                                        <th>Inv Chs Need</th>
                                    </tr>
                                    <?php
                                    if(isset($_SESSION['rec_id']))
                                    {
                                        $sql = "select mainproblem,location,chassisNo,foundby,station,damage_grade,moreinfo,invchss
                                                from dbo.fault_st2_rec
                                                where st2_rec_id like ".$recid."and c_id like 5";
                                        $query = sqlsrv_query($conn , $sql);
                                        if($query === false)
                                        {
                                            die(print_r(sqlsrv_errors(),true));
                                        }
                                        while ($count = sqlsrv_fetch_array($query,SQLSRV_FETCH_ASSOC))
                                        {
                                            echo "<tr>";
                                            foreach($count as $x => $a)
                                            {
                                                echo "<td>".$a."</td>";
                                            }
                                            echo "</tr>";
                                        }
                                    }
                                    ?>
                                </table>
                            </div>
                            <div id="ftlsuk" class="col5">
                                <table>
                                    <tr>
                                        <th>Main Problem</th>
                                        <th>Location</th>
                                        <th>Cause By</th>
                                        <th>Found By</th>
                                        <th>More Info</th>
                                    </tr>
                                    <?php
                                    if(isset($_SESSION['rec_id']))
                                    {
                                        $sql = "select mainproblem,location,causeby,foundby,moreinfo
                                                from dbo.fault_st2_rec
                                                where st2_rec_id like ".$recid."and c_id like 6";
                                        $query = sqlsrv_query($conn , $sql);
                                        if($query === false)
                                        {
                                            die(print_r(sqlsrv_errors(),true));
                                        }
                                        while ($count = sqlsrv_fetch_array($query,SQLSRV_FETCH_ASSOC))
                                        {
                                            echo "<tr>";
                                            foreach($count as $x => $a)
                                            {
                                                echo "<td>".$a."</td>";
                                            }
                                            echo "</tr>";
                                        }
                                    }
                                    ?>
                                </table>
                            </div>
                        </div>
                    </div>
                    <input id="add" class="myButton" type="button" value="Add Problem" onclick="formshow()">
                    <input id="" class="myButton" type="button" value="Back" onclick="recmanu()"/>
                    <div id="addform" class="popupformcontainer">
                        <div class="popupform">
                            <div class="tabbedcontain">
                                <ul class="col2">
                                    <li id="chs" onclick="scchs()">Chassis</li>
                                    <li id="uk" onclick="scuk()">UK</li>
                                </ul>
                            </div>
                            <div class="formcontain">
                                <div id="chsprob">
                                    <form name="chassis" action="php/svfultrec.php" onsubmit="return validateForm('chassis',['mainprob','location','foundby','chsno','station','damg'])" method="post">
                                        <h2>Fault by Chassis</h2>
                                        <table class="fromtable">
                                            <tr>
                                                <td>Main Problem</td>
                                                <td><input name="mainprob" type="text" placeholder="Mainproblem"/></td>
                                            </tr>
                                            <tr>
                                                <td>Location</td>
                                                <td><input name="location" type="text" placeholder="Location"/></td>
                                            </tr>
                                            <tr>
                                                <td>Found By</td>
                                                <td><input name="foundby" type="text" placeholder="Found By"/></td>
                                            </tr>
                                            <tr>
                                                <td>Chassis No</td>
                                                <td><input name="chsno" type="text" placeholder="Chassis No"/></td>
                                            </tr>
                                            <tr>
                                                <td>Station</td>
                                                <td><input name="station" type="text" placeholder="Station"/></td>
                                            </tr>
                                            <tr>
                                                <td>Damage Grade</td>
                                                <td><input name="damg" type="text" placeholder="Damage Grade"/></td>
                                            </tr>
                                            <tr>
                                                <td>More Info</td>
                                                <td><input name="mrinfo" type="text" placeholder="More Info"</td>
                                            </tr>
                                            <tr>
                                                <td>Inv Chs Need ?</td>
                                                <td><input id="checkbox" name="invst" type="checkbox" value="true"/></td>
                                            </tr>
                                            <td colspan="2">
                                                    <input class="myButton" type="submit" value="Add" name="chassis"/>
                                                    <input class="myButton" type="reset" value="Reset"/>
                                                    <input class="myButton" type="button" value="Cancle" onclick="formhide()"/>
                                            </td>
                                        </table>
                                    </form>
                                </div>
                                <div id="ukprob">
                                    <form name="uk" action="php/svfultrec.php" onsubmit="return validateForm('uk',['mainprob','location','foundby'])" method="post">
                                        <h2>Fault by UK</h2>
                                        <table>
                                            <tr>
                                                <td>Main Problem</td>
                                                <td><input name="mainprob" type="text" placeholder="Mainproblem"/></td>
                                            </tr>
                                            <tr>
                                                <td>Location</td>
                                                <td><input name="location" type="text" placeholder="Location"/></td>
                                            </tr>
                                            <tr>
                                                <td>Cause By</td>
                                                <td><input name="causeby" text="text" placeholder="Cause By"/></td>
                                            </tr>
                                            <tr>
                                                <td>Found By</td>
                                                <td><input name="foundby" type="text" placeholder="Found By"/></td>
                                            </tr>
                                            <tr>
                                                <td>More Info</td>
                                                <td><input name="mrinfo" type="text" placeholder="More Info"/></td>
                                            </tr>
                                            <tr>
                                                <td colspan="2">
                                                    <input class="myButton" type="submit" value="Add" name="uk"/>
                                                    <input class="myButton" type="reset" value="Reset"/>
                                                    <input class="myButton" type="button" value="Cancle" onclick="formhide()"/>
                                                </td>
                                            </tr>
                                        </table>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
        </div>
    </body>
</html>

这是关于输入形式。我能提供的任何信息请问我

问题是。。。当变量不为空时,(这意味着php回显'value ='.$date(值不会被我echo的php所取代。

我需要刷新页面以正确显示值。

我也在谷歌chrome的开发工具中签出了查看源代码的代码,事情是。。。。。它被替换了,但每次都需要刷新才能正常显示。

我想做的是,在没有刷新页面或其他事情的情况下,如何获得echo正确显示的值?

//纯js/php将是不错的

已更新在IE渲染输出中正常工作

已更新2我已经写了一些代码,让它再次刷新页面作为临时,我仍然想知道是否有可能在不刷新页面的情况下让它正常显示?

if(isset($_SESSION['refresh']))
    {
        if($_SESSION['refresh'] === true)
        {
            echo "<script> window.location.reload(); </script>";
            $_SESSION['refresh'] = false;
        }
    }

抱歉我的英语不好

感谢

在此处添加双引号或单引号'value='.$date;}

的变化

<input type="text" name="date"<?php if(empty($date)){echo 'id="date"';}else{echo 'value='.$date;} ?> readonly/>

<input type="text" name="date"<?php if(empty($date)) echo 'id="date"'; else echo "value='"$date'""; ?> readonly/>

PHP可以正常工作,但由于生成的html代码包含一些错误,html无法正确呈现输出。根据您的代码,如果$date不为空(例如,它包含17-08-2015(,它将给出如下输出:

<input type="text" name="date"value=17-08-2015 readonly/>

但它应该是这样的:

<input type="text" name="date" value="17-08-2015" readonly/>

因此,更改php代码以生成正确的输出。类似:

<input type="text" name="date" <?php if(empty($date)){echo 'id="date"';}else{echo 'value="'.$date.'";} ?> readonly/>