html5表单validate无效果,html5的验证器(例如<input required>不起作用

我在mvc中工作我有一个窗体使用ajax post,knockout,javascript发布到服务器的视图,名称字段是必需的,并且需要代码字段。形式。因此我用下面的代码名字在我的形式: -html5的验证器(例如不起作用

以下使用JavaScript由我来发布形式

var EmpViewModel = function() {

//Make the self as 'this' reference

var self = this;

//Declare observable which will be bind with UI

self.Code = ko.observable("");

self.Name = ko.observable("");

self.DateOfBirth = ko.observable("");

self.Age = ko.observable("");

self.ContactNumber = ko.observable("");

self.Email = ko.observable("");

self.Address = ko.observable("") ;

self.MaritalStatus = ko.observable("");

self.City = ko.observable("");

self.Reference = ko.observable("");

//The Object which stored data entered in the observables

var EmpData = {

EmpCode: self.Code,

EmpName: self.Name,

Dob: self.DateOfBirth,

Age: self.Age,

ContactNumber: self.ContactNumber,

MaritalStatus: self.MaritalStatus,

EmailID: self.Email,

Address: self.Address,

City: self.City,

Reference: self.Reference

};

//Declare an ObservableArray for Storing the JSON Response

self.Employees = ko.observableArray([]);

//Function to perform POST (insert Employee) operation

this.save = function() {

//Ajax call to Insert the Employee

$.ajax({

type: "POST",

url: "/Exercise/Save/",

data: ko.toJSON(this), //Convert the Observable Data into JSON

contentType: "application/json",

success: function (data) {

alert(data);

window.close();

// opener.location.reload(true);

},

error: function() {

alert("Failed");

}

});

//Ends Here

};

}

ko.applyBindings(new EmpViewModel());

有各种验证存在于我的表格但没有任何作品。表格即使没有填写字段提交?

任何想法来解决这个问题?

+2

你使用什么浏览器?也许它不支持HTML5或此功能。无论如何,你仍然可以自己验证字段,有很多插件和技术。但最后你还需要验证服务器端的数据。 –

2013-03-14 09:27:51

+0

我检查了IE7,Chrome 10和mozila以及.. –

2013-03-14 10:54:00

+1

IE7不支持这种验证,我不确定Chrome 10是什么,但是这听起来也相当古老。当前版本为25. –

2013-03-14 13:39:15

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值