如何使用php获取jquery id值?

时间:2022-11-27 11:24:44
<script>
function startTimer(duration, display) {
    var timer = duration,
        minutes, seconds;

    interval = setInterval(function() {
        minutes = parseInt(timer / 60, 10)
        seconds = parseInt(timer % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        display.text(minutes + ":" + seconds);

        if (--timer < 0) {
            alert("Time has ended");
            $("#registration-form").submit()
            clearInterval(interval);
        }
    }, 1000);

    return new Date();
}

jQuery(function($) {
    s = 10;
    var Minutes = 60 * s,
        display = $('#time');

    var startDate = startTimer(Minutes, display);

    $('button').click(function() {
        var now = new Date();
        var seconds = (now.getTime() - startDate.getTime()) / 1000;
        $('#runtimes').append('<p>' + seconds + '</p>');
    })
});

</script>
<div class="col-md-4">

    <div class="test">Time Left <span id="time"></span>min</div>
</div>

<form name="frmRegistration" id="registration-form" method="post" action="index1.php">
  <div id="runtimes" name="runtime"></div>
<button>Get run time</button>

</form>

https://jsfiddle.net/aruncool/vj84mc40/ in the link displays the value of the already runned time on button click i need to pass the div id value through post and get it into another page and insert the value into db but it is not passing value through the post help me how to get the div id value

https://jsfiddle.net/aruncool/vj84mc40/的链接显示的值已经拼命按钮单击时间我需要通过div id值通过post和get它到另一个页面并将值插入数据库但不是价值通过邮局帮我如何获取div id值

1 个解决方案

#1


4  

You can add an hidden input in your form and update his value when you want.

您可以在窗体中添加隐藏的输入,并在需要时更新其值。

HTML

HTML

<input type="hidden" id="valueoftime" name="valueoftime">

JQuery

JQuery

 $('button').click(
        var now = new Date();
        var seconds = (now.getTime() - startDate.getTime()) / 1000;
        $('#runtimes').append('<p>' + seconds + '</p>');

       //Update input val
        $("#valueoftime").val(seconds);
    })

#1


4  

You can add an hidden input in your form and update his value when you want.

您可以在窗体中添加隐藏的输入,并在需要时更新其值。

HTML

HTML

<input type="hidden" id="valueoftime" name="valueoftime">

JQuery

JQuery

 $('button').click(
        var now = new Date();
        var seconds = (now.getTime() - startDate.getTime()) / 1000;
        $('#runtimes').append('<p>' + seconds + '</p>');

       //Update input val
        $("#valueoftime").val(seconds);
    })