在MVC 3中使用HTML5输入“日期”
HTML5似乎有许多新的输入类型,如许多当前浏览器可用的“date”,如果我把:
Birthday: <input type="date" id="bday", name="bday"/>
它在Chrome上弹出相当不错的日期选择器! 我可以在javascript的帮助下将选定的日期发布到服务器:
updateDate: function() {
var date = $('#bday').val();
var params = { date: date };
$.ajax({
url: '/HelloWorld/updateDateJson',
type: 'POST',
data: JSON.stringify(params),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (result) { $('#timeServer2').text(result); }
//error: function () { $('#ErrorSelfService').text("Ajax error"); }
});
但是,我可以使用视图模型和局部视图以本地asp.net mvc3方式使用它。 一些澄清将不胜感激。
是的,您可以像使用正常字符串值一样使用它。
请注意,虽然其他浏览器可能不支持这个(IE 9 for ex does not),所以仍然建议只使用jQuery UI日期选择器控件和一个用于MM / dd / yyyy输入格式的jquery mask插件(或者任何您支持的文化日期格式)
链接地址: http://www.djcxy.com/p/18657.html上一篇: Using HTML5 input "date" in MVC 3
下一篇: How do I get the value of text input field using JavaScript?