1,文本框失去焦点时若有值则trim
- $('#identityTF').blur(function (e) {
- console.log('blur');
- //去掉首尾的空格
- var eventTarget = e.srcElement || e.target || e.toElement;
- if (eventTarget) {
- var identityTmp = eventTarget.value;
- identityTmp = util.trim(identityTmp);
- if (identityTmp) {
- eventTarget.value = identityTmp;
- }
- }
- })
2,文本框聚焦或有键按下时清除错误样式
- /***
- * 清除错误样式
- * @param event
- */
- var cleanErrorStyle = function (event) {
- var errorClass = 'has-error-inp';
- var eventTarget = event.srcElement || event.target || event.toElement;
- $(eventTarget).removeClass(errorClass);
- };
- $('input[type=text]').keydown(cleanErrorStyle).focus(cleanErrorStyle);
3,如何在事件处理方法中获取事件源(控件)
方式一:
var eventTarget = e.srcElement || e.target || e.toElement;
方式二:
var val=$(this).val();
时间: 2024-11-01 10:59:54