我正在尝试使用我的 jeditable 插件实现 jquery 验证。由于 jeditable 对我来说有点新,我想我会尝试使用我在论坛上找到的代码添加尝试。这是我的原始代码,除了验证之外工作正常。
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="../../Scripts/jquery.jeditable.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.datepicker.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".display-label").editable("/Course/RubricsEdit");
$(".text").editable("/Course/RubricsEdit",
{
submitdata: {
DepartmentId: function () {
return $("#DepartmentId").val();
},
RecordType: "DEPARTMENT"
}
});
然后我尝试了这个:
<script type="text/javascript">
$(document).ready(function () {
$(".display-label").editable("/Course/RubricsEdit");
$(".text").editable("/Course/RubricsEdit",
{
submitdata: {
DepartmentId: function () {
return $("#DepartmentId").val();
},
RecordType: "DEPARTMENT"
}
});
$(".text").editable("/Course/RubricsEdit", {
submitdata: function (settings, td) {
var input = $(td).find('input');
$(this).validate({
rules: {
'nameofinput': {
number: true
}
},
messages: {
'actionItemEntity.name': {
number: 'Only numbers are allowed'
}
}
})
return ($(this).valid());
}
});
});
</script>
仍然有效,但没有发生验证.. 有没有办法让验证与我的 jeditable 插件一起工作?
更新:所以我尝试了这个:
<script type="text/javascript">
$(document).ready(function () {
$(this).validate({
rules: {
submitdata: {
number: true
}
},
messages: {
submitdata: {
number: 'Only numbers are allowed'
}
}
});
$(".display-label").editable("/Course/RubricsEdit");
$(".text").editable("/Course/RubricsEdit",
{
submitdata: {
DepartmentId: function () {
return $("#DepartmentId").val();
},
RecordType: "DEPARTMENT"
}
});
});
</script>
…并收到一条错误消息:
Microsoft JScript 运行时错误:对象不支持属性或方法“验证”。我会错过什么?