我想要计算module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
filerev: {
options: {
algorithm: 'md5',
length: 8
},
images: {
src: ['views/common/abc.html'],
}
},
filerev_replace: {
options: {
assets_root: 'views/common/abc.html'
},
compiled_assets: {
src: 'views/common/abc.html'
},
views: {
options: {
views_root: 'views/'
},
src: 'views/**/*.html'
}
},
useminPrepare: {
html: 'index.html',
options: {
dest: 'indexfolder'
}
},
usemin: {
html: 'indexfolder/index.html',
options: {
dirs: ['views','views1'],
assetsDirs: ['views','views1'],
revmap: ''
}
},
filerev_apply: {
files: [
{
//expand: true,
//cwd: 'views',
src: ['views/**/*.html'],
//dest: 'views'
}
]
},
reload: {
//port: 8000,
proxy: {
host: 'localhost',
port: 80
}
},
watch: {
sass: {
files: ['views/**/*.html'],
tasks: ['reload'],
options: {
livereload: true,
}
}
}
});
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-reload');
grunt.loadNpmTasks('grunt-filerev');
grunt.loadNpmTasks('grunt-filerev-apply');
grunt.loadNpmTasks('grunt-filerev-replace');
grunt.registerTask('default', ['usemin', 'useminPrepare', 'watch','connect', 'reload', 'filerev', 'filerev_apply', 'filerev_replace']);
};
data-validate-func 等于的元素数量(包括select
和input
文本)必需的以及充满价值的人。我尝试了这个,但我不知道填充值的过滤:
attribute
那么如何计算它们?
答案 0 :(得分:1)
由于您希望按属性进行过滤,因此可以使用filter()
方法来实现所需。试试这个:
var count $('[data-validate-func="required"]').filter(function() {
return $.trim(this.value) !== '';
}).length;
请注意,如果您只想将其限制为select
和input
元素,则需要修改主选择器:
var count $('select[data-validate-func="required"], input[data-validate-func="required"]').filter(function() {
return $.trim(this.value) !== '';
}).length;
答案 1 :(得分:0)
var count = $("[data-validate-func='required']").filter(function(){
return $(this).val().length;
}).length;
答案 2 :(得分:0)
从
中删除*
$("*[data-validate-func='required']").length;
到
$("[data-validate-func='required']").length;
或者,如果您只想选择并输入:
$("select[data-validate-func='required'], input[data-validate-func='required']").length;