Last active
August 26, 2017 05:33
-
-
Save guoxiangke/8643863 to your computer and use it in GitHub Desktop.
1.drupal 7,表单如果有必填项没有填写,提交的话,自动focus到未填项。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//form behaviors | |
$('form .form-submit').click(function(e){ | |
$('input.required').each(function(){ | |
if($(this).val()==''){ | |
$(this).focus(); | |
e.preventDefault() | |
return false; | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//默认隐藏注册表单描述,点击显示 | |
$('#user-register-form .form-type-textfield .description').hide(); | |
$('#user-register-form .form-type-textfield ').click(function(){ | |
$(this).children('.description').show(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#user-register-form .form-type-textfield input').blur(function(){ | |
var warning_str = '必须填写'+$(this).prev('label').text().replace('*',''); | |
if($(this).val() == '' && $(this).hasClass('required')) { | |
$(this).parent('.form-type-textfield').children('.description').text(warning_str); | |
}else{ | |
$(this).parent('.form-type-textfield').children('.description').hide(); | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//username min length 2 | |
$('#user-register-form input.username').blur(function(){ | |
if($(this).val().length<2) { | |
if(confirm('用户名至少2个字符')){ | |
$(this).focus(); | |
}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment