在 php 中选择特定日期时更改文本框的值

当在输入类型日期中选择特定日期时,我想更改文本框的数量。当用户点击日期 11 月 2 日时,数量文本框应为 100rs,而当点击星期日数量为 500 时,其他数量为 300。 .我该怎么做 这是代码


<script type="text/javascript">

$(function() {

  $("#txtDate").change(function() {

    var selDate = new Date(this.value);

    if (selDate.getDay() == 0) { //If sunday, can change your logic here

      $(".form-control").val(500);

    } else {

      $(".form-control").val(300);

    }

  })

});

</script>




<input type="date" name="mass_date" id="txtDate" required="required" class="col-md-12"  min="<?php echo date('Y-m-d', strtotime("+2 days")); ?>" max="<?php echo date("Y-m-d", strtotime("2020-09-30"));?>"    value="<?php if(isset($_GET['mass_date'])) { echo $_GET['mass_date']; } ?>" />


<input type="text" class="form-control" id="slDay" name="amount"  />


阿波罗的战车
浏览 104回答 1
1回答

慕仙森

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script type="text/javascript">$(function() {&nbsp; $("#txtDate").change(function() {&nbsp; &nbsp; const selDate = new Date(this.value);&nbsp; &nbsp; const dayOfMonth = selDate.getDate();&nbsp; &nbsp; const month = selDate.getMonth() + 1;&nbsp; &nbsp; const dayOfWeek = selDate.getDay();&nbsp; &nbsp; if (month === 11 && dayOfMonth === 2) {&nbsp; &nbsp; &nbsp; $(".form-control").val(100);&nbsp; &nbsp; }&nbsp; &nbsp; else if (dayOfWeek === 0) {&nbsp; &nbsp; &nbsp; $(".form-control").val(500);&nbsp; &nbsp; }&nbsp; &nbsp; else {&nbsp; &nbsp; &nbsp; $(".form-control").val(300);&nbsp; &nbsp; }&nbsp; })});</script><input type="date" name="mass_date" id="txtDate" required="required" class="col-md-12"&nbsp; min="<?php echo date('Y-m-d', strtotime("+2 days")); ?>" max="<?php echo date("Y-m-d", strtotime("2020-09-30"));?>"&nbsp; &nbsp; value="<?php if(isset($_GET['mass_date'])) { echo $_GET['mass_date']; } ?>" /><input type="text" class="form-control" id="slDay" name="amount"&nbsp; />
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript