PHP更改输入字段中的默认值

时间:2017-01-23 12:54:07

标签: php

我有一个输入字段我想给这个输入一个默认值,但是这个值也可以由用户改变

这里我把一个默认值放在问题上,如果用户选择了另一个值,默认值仍会出现。

我如何显示一个值,当用户更改此值时,它将保存。

这是一个日期,我使用日期时间选择器来自此datetimepicker,用户选择他的值。

<input type="text" value="<?php if(!isset($_POST['txt_psd'])){echo date('Y-m-d H:i:s');} ?>" id="datetimepicker1" name="txt_psd" />



  <script type="text/javascript">
                $(function () {
                    $('#datetimepicker1').datetimepicker()
                });
            </script>
<script type="text/javascript">
    function GetDays() {
        var timeStart = new Date(document.getElementById("datetimepicker1").value);
        var timeEnd = new Date(document.getElementById("datetimepicker2").value);
        var hourDiff = timeEnd - timeStart; //in ms
        var secDiff = hourDiff / 1000; //in s
        var minDiff = hourDiff / 60 / 1000; //in minutes
        var hDiff = hourDiff / 3600 / 1000; //in hours
        var DayDiff = hourDiff / 3600 / 1000 / 24; //in days
        var humanReadable = {};
        humanReadable.Days = Math.floor(DayDiff);
        humanReadable.hours = Math.floor(hDiff - 24 * humanReadable.Days);
        humanReadable.minutes = Math.floor(minDiff) - (60 * humanReadable.hours + 24 * 60 * humanReadable.Days);
        return humanReadable;

    }

    function cal() {
        if (document.getElementById("datetimepicker2")) {
            var Human = GetDays();
            document.getElementById("duration").value = Human.Days + " Days " + Human.hours + " hours " + Human.minutes + " minutes" ;
        }
    }
</script>

0 个答案:

没有答案