gpt4 book ai didi

javascript - 如何在文本框中获取上一个和下一个日期

转载 作者:行者123 更新时间:2023-11-30 13:01:30 24 4
gpt4 key购买 nike

我有一个文本框和两个按钮。

  • button1 name as prev,
  • button2 命名为 next
  • 文本框 包含当前日期
If I click in next button the textbox will show the next date.
If I click in prev button the textbox will show the previous date.

请帮帮我...

enter code here
<input type="text" id="txtDateFilter" readonly="readonly" runat="server" />

<div id="sfprevbtn" title="Prev" class="fbutton">
<span class="fprev"></span>
</div>
<div id="sfnextbtn" title="Next" class="fbutton">
<span class="fnext"></span>
</div>

<script type="text/javascript">
$('#sfprevbtn').click(function(e)
{
$('#txtDateFilter').val();
});

$('#sfnextbtn').click(function(e)
{
$('#txtDateFilter').val();
});
</script>

最佳答案

看看我制作的这个 fiddle :http://jsfiddle.net/TV57Q/

我利用了 javascript 本身的 Date 对象。

var date = new Date();
$(function () {
// This writes out the current date to the text field as starter
$('#field').val(date.toLocaleDateString());

// Hook up previous button event
$('#prev').click(function () {
// Set our current date to 1 day earlier
date.setDate(date.getDate() - 1);
// Write the result to our text input
$('#field').val(date.toLocaleDateString())
});
// Hook up next button event
$('#next').click(function () {
// Set our current date to 1 day later
date.setDate(date.getDate() + 1);
// Write the result to our text input
$('#field').val(date.toLocaleDateString())
});
});

关于javascript - 如何在文本框中获取上一个和下一个日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17292612/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com