如何添加日期选择器当我单击文本框
How to add DatePicker when I click on text box?
在我的MVC4剃刀引擎中,我需要从文本框中选择日期。我的观点是:
<tr>
<td>Start Date</td>
<td>@Html.TextBox("RateListStartDate")</td>
</tr>
<tr>
<td>End Date</td>
<td>@Html.TextBox("RateListEndDate")</td>
</tr>
当我单击开始日期或结束日期的文本框时,它应该显示日历。
由于你使用MVC,jQuery"应该"已经在你的布局页面中引用了。您还需要 jqueryUI。
如果日期选取器代码向您抛出错误,请将以下 2 行添加到您的视图或布局页面:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
然后,您需要声明元素,这些元素应该是获取日期选择器功能。
$(document).ready(function(){
$(".getdate").each(function() {
$(this).datepicker();
});
});
并相应地编辑您的 Html.TextBoxFor():
@Html.TextBox("RateListStartDate", new {@class="getdate"})
这应该可以解决问题。亲切问候
你可以使用 jquery datepicker。日期选择器演示
$(document).ready(function(){
$(".datepicker").each(function() {
$(this).datepicker();
});
});
斯菲德尔
<!doctype html>
<head>
<meta charset="utf-8" />
<title>jQuery UI Datepicker - Restrict date range</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker({ minDate: -100, maxDate: "+0D" });
$("#datepicker").datepicker("setDate",new Date());
$( "#datepicker" ).datepicker( "option", "dateFormat", "dd/mm/yy");
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker" /></p>
</body>
</html>
$(document).ready(function () {
$('#txtBoxId').datepicker();
});
请参阅您的布局
@Scripts.Render("~/bundles/jqueryui")
<script>
$(function()
{
$("#date").datepicker();
$("#date").datepicker
({
dateFormat: "dd-mm-yyyy"
});
});
</script>
<tr>
<td>Start Date</td>
<div class="form-group">
@Html.LabelFor(model => model.date, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.date, new { htmlAttributes = new { @class = "date" } })
@Html.ValidationMessageFor(model => model.date, "", new { @class = "text-danger" })
</div>
</div>
</tr>
<tr>
<td>End Date</td>
<div class="form-group">
@Html.LabelFor(model => model.date, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.date, new { htmlAttributes = new { @class = "date" } })
@Html.ValidationMessageFor(model => model.date, "", new { @class = "text-danger" })
</div>
</div>
</tr>
相关文章:
- 单击文本时删除文本框的默认数据
- 如何在单击文本时将其更改为文本框
- 通过单击文本更改图片
- 如何在Windows 7/8中通过单击文本输入来显示屏幕键盘
- HTML隐藏输入值随javascript和单击文本而更改
- 单击文本输入时如何执行某些操作
- 当我单击文本框时,如何获得几天的日期
- 如何使用Angularjs动态单击文本框
- 在复选框类型中单击文本框后选择文本框
- 单击文本框后启用提交按钮
- 以编程方式触发空格键单击文本区域
- 单击文本区域可隐藏标签值
- jQuery onClick 事件有效,除非单击文本
- 单击文本框的右键单击上下文菜单的“删除”后触发的事件
- 使用 jquery 单击文本链接
- 如何添加日期选择器当我单击文本框
- 如何单击文本区域,然后使用 jquery 按空格键
- 更改事件中的 METEOR 仅在您单击文本区域后才会在文本区域上触发
- 单击文本时未提交的表单
- 如何让用户通过单击文本来增加字体大小