Javascript 从日期选择器发出填充标签并计算
今天我已经在这方面工作了一段时间,我被难住了。我正在尝试使用日期选择器选择一个日期,并获取该日期,用它填充标签,还获取用户的输入,以向所选日期添加天数。日期选择器工作正常,但是我无法获得填充标签的日期,我不确定如何计算,比如说提前6天计算该日期。添加天数的代码很简单,我不确定如何计算日期 以下是我到目前为止的情况: 看法 模型Javascript 从日期选择器发出填充标签并计算,javascript,asp.net-mvc,razor,jquery-ui-datepicker,Javascript,Asp.net Mvc,Razor,Jquery Ui Datepicker,今天我已经在这方面工作了一段时间,我被难住了。我正在尝试使用日期选择器选择一个日期,并获取该日期,用它填充标签,还获取用户的输入,以向所选日期添加天数。日期选择器工作正常,但是我无法获得填充标签的日期,我不确定如何计算,比如说提前6天计算该日期。添加天数的代码很简单,我不确定如何计算日期 以下是我到目前为止的情况: 看法 模型 等等,那么是不是日期计算不正确?因此,当您添加“6”天时,结果不正确?我很难理解您的代码。例如,在两个不同的位置初始化datepicker,并有一个按钮单击事件,但表单上
等等,那么是不是日期计算不正确?因此,当您添加“6”天时,结果不正确?我很难理解您的代码。例如,在两个不同的位置初始化datepicker,并有一个按钮单击事件,但表单上没有按钮。另外,var DaysToBeAdded=addDaysEntered;addDaysEntered定义在哪里?日期选择器显示所选日期,我无法获取该日期并向其添加天数以显示新日期。@paul.abbott.wa.us-以下日期选择器存在,因为如果我只有上一个初始化,则日期选择器无法正确呈现。这可能是因为在document.ready中,选择器日期为小写,id为大写。
@{
ViewBag.Title = "Index";
}
<link type="text/css" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<form id="calendarForm" action="~/Views/Calendar/Calendar.cshtml" method="post">
<h2>Calendar Application</h2>
<p>This application will display a the specified number of days <br /> the user inputs on a calendar.</p>
<br />
<h2>Select A Date</h2>
@model VanickCalendarApp.Models.Calendar
<!-- Date picker visible -->
<p>
<input type="text" id="Date" />
</p>
<!-- Takes the date from the picker and calculates it new date on button click-->
<script>
$('button').click(function () {
var datePickerSelected = $("#Date").datepicker("getDate");
var endDate = new Date();
var selDate = $('#Date').val();
var DaysToBeAdded = addDaysEntered;
endDate = (selDate + DaysToBeAdded);
});
</script>
@using (Html.BeginForm("Calculate Days", "Calendar", FormMethod.Post))
{
<h2>Enter The Number Of Days To Display</h2>
@Html.TextBoxFor(model => model.DaysToBeViewed)
<label id="dateSelected">"Date"</label>
<input type="button" value="Submit" onclick="daysAdded()" />
}
<!-- Create the date picker script -->
<script>
$(function () {
$('#Date').datepicker();
});
</script>
<!-- Creates an alert to test the values for debuging -->
<script>
document.getElementById('dateSelected').valueOf = dateSelected
alert.valueOf("Date");
</script>
</form>
using System.Web.Mvc;
using VanickCalendarApp.Models;
namespace VanickCalendarApp.Controllers
{
public class CalendarController : Controller
{
public string CalculateDays(string Date)
{
var oneDAY = 1000 * 60 * 60 * 24;
return Date;
}
//
// GET: /Calendar/
public ActionResult Calendar()
{
return View();
}
//
// GET: /Calendar/Details/5
public ActionResult Details(int id)
{
return View();
}
//
// GET: /Calendar/Create
public ActionResult Create()
{
return View();
}
//
// POST: /Calendar/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /Calendar/Edit/5
public ActionResult Edit(int id)
{
return View();
}
//
// POST: /Calendar/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /Calendar/Delete/5
public ActionResult Delete(int id)
{
return View();
}
//
// POST: /Calendar/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
using System;
using System.Web.Mvc;
using System.Data;
using System.Data.Entity;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
namespace VanickCalendarApp.Models
{
public class Calendar
{
//[DataType(DataType.Date)]
public string date { get; set; }
public int DaysToBeViewed { get; set; }
public DateTime newDate { get; set; }
}
}