0

我在 h3 标签中有一个日期,我试图使用我的代码隐藏文件中的一些功能来抓取并转换为另一个日期。我如何在jquery中完成这个?

HTML

<div id="firstweekwrapper" class="weekcontainer">
                        <div id="day1" class="daytile daytilefirst">
                            <h3 id="day1date" class="dateh3"><%=FirstTradingDayInMonth(DateTime.Now.Date).ToLongDateString()%></h3><br />
                            <p id="day1equities"><span class="targettext"> <span class="bluetext">Equities</span> Target PnL:&nbsp;</span><span id="day1equitytargetvalue" class="targettext"></span><br /><span class="actualtext">Actual <span class="bluetext">Equities</span> PnL:&nbsp;</span><span id="day1equityactualvalue" class="actualtext"></span></p>
                            <p id="day1options"><span class="targettext"> <span class="bluetext">Options</span> Target PnL:&nbsp;</span><span id="day1optiontargetvalue" class="targettext"></span><br /><span class="actualtext">Actual <span class="bluetext">Options</span> PnL:&nbsp;</span><span id="day1optionactualvalue" class="actualtext"></span></p>
                            <p id="day1futures"><span class="targettext"> <span class="bluetext">Futures</span> Target PnL:&nbsp;</span><span id="day1futuretargetvalue" class="targettext"></span><br /><span class="actualtext">Actual <span class="bluetext">Futures</span> PnL:&nbsp;</span><span id="day1futureactualvalue" class="actualtext"></span></p>
                        </div>
                        <div id="day2" class="daytile">
                            <h3 id="day2date" class="dateh3"></h3><br />
                            <p id="day2equities"><span class="targettext"> <span class="bluetext">Equities</span> Target PnL:&nbsp;</span><span id="day2equitytargetvalue" class="targettext"></span><br /><span class="actualtext">Actual <span class="bluetext">Equities</span> PnL:&nbsp;</span><span id="day2equityactualvalue" class="actualtext"></span></p>
                            <p id="day2options"><span class="targettext"> <span class="bluetext">Options</span> Target PnL:&nbsp;</span><span id="day2optiontargetvalue" class="targettext"></span><br /><span class="actualtext">Actual <span class="bluetext">Options</span> PnL:&nbsp;</span><span id="day2optionactualvalue" class="actualtext"></span></p>
                            <p id="day2futures"><span class="targettext"> <span class="bluetext">Futures</span> Target PnL:&nbsp;</span><span id="day2futuretargetvalue" class="targettext"></span><br /><span class="actualtext">Actual <span class="bluetext">Futures</span> PnL:&nbsp;</span><span id="day2futureactualvalue" class="actualtext"></span></p>
                        </div>
                         <div id="day3" class="daytile">
                            <h3 id="day3date" class="dateh3"></h3><br />
                            <p id="day3equities"><span class="targettext"> <span class="bluetext">Equities</span> Target PnL:&nbsp;</span><span id="day3equitytargetvalue" class="targettext"></span><br /><span class="actualtext">Actual <span class="bluetext">Equities</span> PnL:&nbsp;</span><span id="day3equityactualvalue" class="actualtext"></span></p>
                            <p id="day3options"><span class="targettext"> <span class="bluetext">Options</span> Target PnL:&nbsp;</span><span id="day3optiontargetvalue" class="targettext"></span><br /><span class="actualtext">Actual <span class="bluetext">Options</span> PnL:&nbsp;</span><span id="day3optionactualvalue" class="actualtext"></span></p>
                            <p id="day3futures"><span class="targettext"> <span class="bluetext">Futures</span> Target PnL:&nbsp;</span><span id="day3futuretargetvalue" class="targettext"></span><br /><span class="actualtext">Actual <span class="bluetext">Futures</span> PnL:&nbsp;</span><span id="day3futureactualvalue" class="actualtext"></span></p>
                        </div>

我正在尝试使用我的代码隐藏文件中的 AddBusinessDay 函数将 day2date id 的值设置为下一个工作日。我对使用 jquery 有点陌生,所以我不确定如何使用隐藏文件中的代码中的 vb.net 代码进行合并。

4

1 回答 1

0

我真的认为您应该在服务器端执行此操作,但如果您打算使用 javascript 执行此操作,则可以执行以下操作:

  • 将日期字符串解析为日期对象
  • 增加一天
  • 将日期转换回格式化的日期字符串

演示

$("button").click(function () {
    var _date = Date.parse($("#day1date").text());
    $("#day2date").text(FormattedDate(_date, 1));
    $("#day3date").text(FormattedDate(_date, 2));
    $("#day4date").text(FormattedDate(_date, 3));
    $("#day5date").text(FormattedDate(_date, 4));
    $("#day6date").text(FormattedDate(_date, 5));
});

var d_names = new Array("Sunday", "Monday", "Tuesday",
    "Wednesday", "Thursday", "Friday", "Saturday");

var m_names = new Array("January", "February", "March",
    "April", "May", "June", "July", "August", "September",
    "October", "November", "December");

function FormattedDate(_date, _addDays) {
    var d = _date + (86400000 * _addDays); //86400000ms = 1day
    d = new Date(d);
    var returnDate = d_names[d.getDay()] + ", " + m_names[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
    return returnDate;
}
于 2013-06-11T19:26:47.357 回答