js无法正常工作
<input id="files" type="file" name="files[]" multiple/>
我的js是...
$("#GallaryForm").validate({
rules:
{
event_id:
{
required: true,
},
files:
{
required: true,
},
},
messages:
{
event_id:
{
required: 'Please Select Event .',
},
files:
{
required: 'Please Upload Image or Video.',
},
},
});
帮帮我 在文件上 验证 它不是 工作中...
答案 0 :(得分:2)
字段名称应该用单引号引起来。
'files[]':
{
required: true,
}
和
'files[]':
{
required: 'Please Upload Image or Video.'
}
您的代码应类似于
$("#GallaryForm").validate({
rules: {
event_id: {
required: true, // <-- this comma is not required
},
'files[]': {
required: true, // <-- this comma is not required
}, // <-- this comma is not required
},
messages: {
event_id: {
required: 'Please Select Event .', // <-- this comma is not required
},
'files[]': {
required: 'Please Upload Image or Video.', // <-- this comma is not required
}, // <-- this comma is not required
}, // <-- this comma is not required
});
答案 1 :(得分:1)
您应该在单引号中加上元素的名称,以在jquery验证中应用规则和消息
$("#GallaryForm").validate({
rules: {
event_id: {
required: true,
},
'files[]': {
required: true,
},
},
messages: {
event_id: {
required: 'Please Select Event .',
},
'files[]': {
required: 'Please Upload Image or Video.',
},
},
});