【问题标题】:Display single date on a textbox having prev and next buttons在具有上一个和下一个按钮的文本框中显示单个日期
【发布时间】:2014-07-29 16:07:16
【问题描述】:

我正在使用 php MySql。
如何在单个文本框中显示下一个上一个日期。
场景是 - 我在某个日期使用 mysql 获取 some data(string)。我想在各自的日期显示各自的数据。


2014 年 9 月 6 日 - “早安”
2014 年 10 月 6 日 - “晚安”。

<input type="button" value="prev">
<input type="text">
<input type="button" value="next">


<span class="date_data"></span> //To display data


假设 - 我有 6 月 8 日的“早安”字符串......以及 6 月 20 日的“晚安”。所以当我选择 8th 时,按 prev 应该会显示“早安”。同样,当我去 20 时。它应该显示“晚安”

My JSFIDDLE

【问题讨论】:

  • 你是将mysql数据存储在json还是某个对象中以在html中显示?
  • 我没有使用 json.. 我正在存储在某个对象中..
  • 所以也请分享该目标代码,您如何在页面中使用它。以便我们更好地帮助您。
  • $bstm=array();而($row3 = mysql_fetch_assoc($result)) { $bstm[$row3['id']] = $row3; } 返回 $bstm;
  • 并且 $bstm 包含日期和相​​应的字符串。

标签: php jquery mysql date datepicker


【解决方案1】:

假设您的 json 数据具有类似这样的格式,

var date = [{
        "Date": "09/06/2014",
        "Message": "Good Morning"
    },

    {
        "Date": "10/06/2014",
        "Message": "Good Night"
    }, {
        "Date": "11/06/2014",
        "Message": "Good Evening"
    }
];
var index = 0;
$("#prev").click(function () {

    $("#txt").val(date[index].Date);
    $("#msg").html(date[index].Message);
    index--;

});
$("#next").click(function () {

    $("#txt").val(date[index].Date);
    $("#msg").html(date[index].Message);
    index++;
});

Fiddle

【讨论】:

  • 好的,就像你说的那样。我的数据是 JSON 格式的。我只是想将这些日期数据与 jquery datepicker 进行比较。我该如何实现?
猜你喜欢
  • 2023-03-05
  • 1970-01-01
  • 1970-01-01
  • 2022-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
相关资源
最近更新 更多