谁能告诉我如何在以下上下文中调用函数 GetDuration:
@{
...
...
<div> GetDuration(@item.StartDate, @item.EndDate) </div>
...
...
}
该函数GetDuration()
在我的上下文中提到的父 DIV 内动态创建另一个 DIV。
我有两个问题:
- 我不知道如何
GetDuration()
从代码中显示的位置调用我的函数 startdatum.Month.ToString("MMMM");
返回"MMMM"
而不是月份的名称
提前致谢!
这是我的代码:
<script type="text/javascript">
function GetDuration(startdatum, einddatum) {
var maand1 = startdatum.Month.ToString("MMMM");
var maand2 = einddatum.Month.ToString("MMMM");
var duration = "Date: ";
if (maand1 == maand2) {
duration += item.Startdate.Day.ToString()
+ " - " + item.Enddate.Day.ToString()
+ " " + maand1
+ " " + item.Startdate.Year.ToString();
}
else {
duration += item.Startdate.Day.ToString()
+ item.Startdate.Month.ToString("MMMM")
+ " - " + item.Enddate.Day.ToString()
+ " " + item.Enddate.Month.ToString("MMMM")
+ " " + item.Startdate.Year.ToString();
}
var dynDiv = document.createElement("div");
dynDiv.class = "HP_DateDiv";
dynDiv.innerHTML = duration;
document.body.appendChild(dynDiv);
}
</script>
@{ string prevYear = "";
foreach (var item in ViewData.Model) {
string year = item.StartDate.Year.ToString();
if (year != prevYear)
{
<div class="contentheader">
@year Formula 1 Tickets
</div>
prevYear = year;
}
<div class="HP_eventBodyDiv">
<div class="HP_picDiv" style = "width:100px; height:100px;">
<a href="http://www.cssdrive.com/" class="highlightit"><img src="../../Content/Pics/auto.jpg" alt="oto" height="50" width="50"/></a>
</div>
<div class="HP_eventDiv">
<div class="HP_eventNameDiv">@item.Name
</div>
<!--This is the spot to call my function with something like "GetDuration(@item.StartDate, @item.EndDate)"-->
<div class="HP_viewBuyBtnsDiv">
<input id="btn_View" type="button" value="View Event" class="contentbtn"/>
<input id="btn_Buy" type="button" value="Buy Tickets" class="contentbtn"/>
</div>
</div>
</div>
};
}