mvc html5 input,在MVC 3中使用HTML5输入“date”(Using HTML5 input “date” in MVC 3)

在MVC 3中使用HTML5输入“date”(Using HTML5 input “date” in MVC 3)

HTML5似乎有许多新的输入类型,如“date”可用于许多当前的浏览器,如果我把:

Birthday:

它在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方式使用它。 一些澄清将不胜感激。

HTML5 seems to have new input types like "date" available for many current browser, if I put:

Birthday:

it pops up quite good date picker on Chrome! I could post selected date to server with help of 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"); }

});

But then can I use it in a native asp.net mvc3 way using view model and partial view. Some clarification will be appreciated.

原文:https://stackoverflow.com/questions/14033383

更新时间:2019-12-01 21:46

最满意答案

是的,你可以像刚刚发布的普通字符串值一样使用它。

请注意,虽然其他浏览器可能不支持这个(IE 9 for ex doesnt)所以仍然建议只使用jQuery UI日期选择器控件和jquery掩码插件为MM / dd / yyyy输入格式(或任何支持的文化为日期格式)

Yes you can use it in the same way as it is just posted as a normal string value.

Note though that other browsers may not support this (IE 9 for ex doesnt) so is still recommend just using the jQuery UI date picker control with a jquery mask plugin for MM/dd/yyyy input format (or whatever your supported cultures are for date format)

相关问答

据我所知,我们在Opera中所做的背后的思想(完全公开:我为他们工作)是日期选择器几乎是Chrome浏览器本地控件的扩展。 因此,它将根据浏览器的语言进行本地化,而不是正在查看的页面的语言。 From what i know, the thinking behind what we do in Opera (full disclosure: I work for them) is that the date picker is almost an extension of the chrome,

...

正如你的文章和评论所指出的,没有理由不使用这种输入类型。 对于不支持type="date"浏览器,该属性将被忽略,并且该字段将呈现为type="text" ,因为这是默认值。 你会想验证那个日期服务器端。 记住:任何人都可以在脚本中发布任何内容。 您仍然可以验证数据客户端。 这里有检测HTML5表单支持的方法: http : //nicolahibbert.com/html5-forms-support-detection-javascript/ As pointed out in your ar

...

根据Thymeleaf + Spring教程 th:field生成的代码与设置id和name标签的代码相同:

等效代码:

也许你需要删除id=datepicker0到executionDate并绑定id=datepicker0上的cl

...

只是一个头脑,其中许多现在通过使用DataType属性并入MVC4。 可以使用以下工作项目 : public class MyModel

{

// Becomes

public int ID { get; set; }

// Becomes

[DataType(DataType.Url)]

public string WebSite { get; set

...

是的,你可以像刚刚发布的普通字符串值一样使用它。 请注意,虽然其他浏览器可能不支持这个(IE 9 for ex doesnt)所以仍然建议只使用jQuery UI日期选择器控件和jquery掩码插件为MM / dd / yyyy输入格式(或任何支持的文化为日期格式) Yes you can use it in the same way as it is just posted as a normal string value. Note though that other browsers may

...

是的,可以使用简单的html输入标签。 在表单标记中添加这样的commandName属性

现在在你的控制器类中添加像这样的@ModelAttribute 。 @RequestMapping(value="create" , method=RequestMe

...

它可以通过两种方式完成: 通过剃须刀渲染“@”:

使用HTML编码:

It can be done 2 ways: Render the "@" through

...

为什么只是使用如下所示的html helper: - @Html.TextBox("txtJoiningDate", Model.JoiningDate.Value ,"{0:yyyy-MM-dd}",new{ @style="width:100%", type="date" })

Why instead you just use html helper as shown :- @Html.TextBox("txtJoiningDate", Model.JoiningDate.Value ,"{

...

Spring不关心你在jsp文件中使用什么标签。 浏览器呢。 为HTML5使用正确的文档类型是:

Spring doesn't care what tags you use in your jsp files. The browser does. Use a correct document type for HTML5 is all:

您需要将您的术语val解析为整数 - parseInt(terms) 。 小提琴 。 $('#terms').on('blur', function() {

var terms = $("#terms").val();

var date = new Date($("#date").val());

date.setDate(date.getDate() + parseInt(terms));

var day = ("0" + date.getDate()).slice

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值