将javascript var传递给php

时间:2014-05-31 00:04:33

标签: javascript php

我在js中有一个crono应用程序,但我需要将该var传递给php中的模态,我有这个(它是一个嵌入表)

<table>
    <thead>

    <th>Project</th>
    <th>Task</th>
    <th>Tieme</th>
    <th><th>      
    </thead>
    <tbody>
    <tr>
        <td>".$res[0]."</td>
        <td>".$res[1]."</td>
        <td > <form name='crono' class='large-6'>
    <input type='text' name='face' title='Cronomet'>
    <script type='text/javascript'>
    var timeCrono;

        var hor = 0;
        var min = 0;
        var seg = 0;
        var startTime = new Date();
        var start = startTime.getSeconds();

        var startchron = 0;

        StartCrono();


        function StartCrono() {

          if (startchron == 1) {

            if (seg + 1 > 59) {
                min += 1;
            }
            if (min > 59) {
                min = 0;
                hor += 1;
            }
            var time = new Date();
            if (time.getSeconds() >= start) {
                seg = time.getSeconds() - start;
            }
            else {
                seg = 60 + (time.getSeconds() - start);
            }
            timeCrono = (hor < 10) ? '0' + hor : hor;
            timeCrono += ((min < 10) ? ':0' : ':') + min;
            timeCrono += ((seg < 10) ? ':0' : ':') + seg;
            document.crono.face.value = timeCrono;
            setTimeout('StartCrono()', 1000);
             console.log(timeCrono);

        } 
     }   
    function stopChr() {
       startchron = 0;
     $('#data').text(timeCrono);
    }     

    function startChr() {
        startchron = 1;
        StartCrono();
    } 

    </script>
</form> 

</td>   

        <td><input type='button' id='btnstart'onclick='startChr();' class='button' value='START'></td> 
        <td> <a href='#' data-reveal-id='ventana' id='addhrs'><input type='button' id='btnstop'onclick='stopChr();' class='button' value='STOP'></a></td> 
    </tr>
    </tbody>
</table>";

我需要&#39; timeCrono&#39;格式为00:00:00的值,当按下停止按钮(函数stopChr)时,显示一个带有信息的模态,我所拥有的是该值的文本$(&#39; #data&#39;)。 (timeCrono);

  

但是我需要将该文本传递给a或类似的值#data是一个标签<p id='data'></p>,我想要的结果就像是    <p id='data' value='00:00:00'>.

1 个答案:

答案 0 :(得分:2)

为了将值从JavaScript传递到服务器端代码(例如PHP),您需要通过网络发送值。

Ajax是执行此操作的方法之一,jQuery makes it easy可以执行Ajax查询。

相关问题