1

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

  • button1名称为prev,
  • button2命名为next.
  • textbox包含current date.
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>
4

1 回答 1

3

看看我制作的这个小提琴: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())
    });
});
于 2013-06-25T10:22:34.880 回答