pei*_*rix 43
只需检查在使用jQuery搜索时有多少元素
if ($(".Mandatory").length > 0) {
// Do stuff with $(".Mandatory")
$(".Mandatory").each(function() {
// "this" points to current item in looping through all elements with
// class="Mandatory"
$(this).doSomejQueryWithElement();
});
}
Run Code Online (Sandbox Code Playgroud)
编辑 如果你想检查你的提交按钮点击,只需点击后进行检查:
$("input[type='submit']").click(function() {
if ($(".Mandatory").length > 0) {
// Do some code here
}
});
Run Code Online (Sandbox Code Playgroud)
Rus*_*ell 11
如果您只想执行一次操作,可以使用:
if ($('.Mandatory').length > 0) {
//do your thing
}
Run Code Online (Sandbox Code Playgroud)
否则,如果您想为每个Mandatory元素执行此操作:
$('.Mandatory').each(function(){
//do your thing
});
Run Code Online (Sandbox Code Playgroud)
执行此操作的最佳方法是在body标记内进行搜索.
$('body').find('.Mandatory').length;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56526 次 |
| 最近记录: |