Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 设置模式中日期输入类型框的当前日期_Javascript_Jquery_Html_Bootstrap Modal - Fatal编程技术网

Javascript 设置模式中日期输入类型框的当前日期

Javascript 设置模式中日期输入类型框的当前日期,javascript,jquery,html,bootstrap-modal,Javascript,Jquery,Html,Bootstrap Modal,在我的页面上,我有一个以模态打开的表单。它有几个字段,日期是其中之一。我想将其设置为默认的今天日期。我的模型可以在下面看到 <!--main modal--> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-c

在我的页面上,我有一个以模态打开的表单。它有几个字段,日期是其中之一。我想将其设置为默认的今天日期。我的模型可以在下面看到

    <!--main modal-->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header" style ="background-color: #38BFEF;">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title"><center><font color="white">New Food Delivery</font></center></h4>
        </div>
        <div class="modal-body">

 <!---inside pop up content start-->
  <form>
  <center>
    <p>
        <label for="Delivery Number">Delivery Number:</label>
        <input type="text" name="delivery_number" id="delNumber" style="width:150px;" autofocus="autofocus">
    </p>
    <p>
        <label for="Delivery Date">Delivery Date:</label>
        <input type="date" name="datepicker" style="margin-left:4%;width:150px;" id="datepicker">
    </p>
    <p>
        <label for="Supplier">Supplier:</label>
        <input type="text" name="supplier" style="margin-left:10%;width:150px;" id="supplier">
    </p>
     <p>
        <label for="Supplier">Cost of Delivery:</label>
        <input type="text" name="cost" style="margin-left:1%;width:150px;" id="cost">
    </p>
    </center>
    <center><input type="button"  id="submit" class="btn btn-info btn-lg vbtn" value="Submit" onclick="submitDelivery()" data-toggle="modal" data-target="#confirmModal"></center>
</form>


 <!---inside pop up content end-->
       </div>
        <div class="modal-footer" style ="background-color: #38BFEF;">
          <input type="button" id="close" class="btn btn-default" data-dismiss="modal" value="Cancel">
        </div>
      </div>

    </div>
    </div>
然而,当我在Chrome中打开模式时,框中仍然显示dd/mm/yyyy,似乎该功能无法正常工作


另一个问题是,当我在Firefox中打开上述代码时,它似乎无法将日期框识别为日期输入类型。

在表单中,您的id是日期选择器,并且您试图访问日期picker(注意大写字母p)使用jquery。

在表单中,您有id作为日期选择器,并且您正试图使用jquery访问日期picker(注意大写字母p)。

而不是使用
DD/MM/yyyyy
您需要使用格式
YYYY-MM-DD

因此,结果字符串将是:

 var today = (now.getFullYear() + '-' + month + '-' + day);
 $('#datepicker').val(today);

下面是一个工作示例:

不使用
DD/MM/YYYY
您需要使用格式
YYYY-MM-DD

因此,结果字符串将是:

 var today = (now.getFullYear() + '-' + month + '-' + day);
 $('#datepicker').val(today);

下面是一个工作示例:

True,我错过了那个。我现在更改了它,但它似乎仍然没有在Chrome中设置日期。它似乎在Firefox中工作,但正如我所说,Firefox不识别输入类型为日期。@ArtleMaks ctrl+shift+r(或cmd+shift+r)刷新chrome中缓存的js。jquery在两种浏览器中的性能应该相同。@iwrestledabearon。我也会这么想,但事实似乎并非如此。你能试着在Firefox和Chrome中打开它,这样我就可以看看它是否是我这边的东西了吗?@ArtleMaks-确认,你是对的,在FF中工作,Chrome显示了这个错误:
jquery.min.js.download:4指定的值“13/01/2017”不符合要求的格式,“yyyyy-MM-dd”。
试试这个:
var-today=now.getFullYear()+“-”+(月)+“-”+(天);
@Iwrestledabearonce。你是个天才,完成了这项工作。嗯,差不多了。我只需要使用var today=now.getFullYear()+“-”+(月)+“-”+(天);谢谢你们两位的输入和帮助!没错,我错过了那个。我现在更改了它,但在Chrome中似乎仍然没有设置日期。它在Firefox中似乎可以工作,但正如我所说,Firefox无法识别输入类型为日期。@ArtleMaks ctrl+shift+r(或cmd+shift+r)在chrome中刷新缓存的js。jquery在两种浏览器中的性能应该是相同的。@IWRestleDabearon。这是我的想法,但似乎不是这样。你能试着在Firefox和chrome中打开它,让我看看它是否对我有利吗?@ArtleMaks-确认,你是对的,在FF中工作,chrome显示此错误:
jquery.min.js.download:4指定的值“13/01/2017”不符合要求的格式“yyyy-MM-dd”。
试试这个:
var-today=now.getFullYear()+“-”+(month)++“-”+(month)+-“+”+(day);
@iwrestledaberon。你是个天才,完成了这项工作。好吧,差不多了。我只是今天不得不使用var=now.getFullYear()+“-”+”(month)+(month)+(month)+(month)+-“+”+”+(day);感谢你们两位的投入和帮助!