js检测form表单 required="required"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<form method="post" id="saveTranslationItemForm">
<div class="form-group">
<label for="newTextSelect"><?php echo __("New Text")?></label>
<input type="text" id="newTextSelect" class="form-control" required="required" placeholder="<?php echo __("New Text")?>" name="trans[new_text]">
</div>
<button type="button" class="btn btn-primary translation_save" ><?php echo __("Save")?></button>
</form>
<script type='text/javascript'>
$(document).ready(function(){
$(document).on('click','.translation_save',function(){
var flag = 1;
$('#saveTranslationItemForm :input:visible[required="required"]').each(function(){
if(!this.validity.valid) {
$(this).focus();
// break
flag = 0;
return false;
}
});
if(!flag){
return false;
}
)
});
</script>

 

坚持原创技术分享,您的支持将鼓励我继续创作!