JS控制输入框以红色作为验证提示,遇到两个问题:
- select标签和input标签有区别
- focus后变红再恢复时,不好恢复到之前的带有阴影的蓝边框
解决方案:
- 第一种写法
function focusChangeBorder( id ) {
var editElem = $("#" + id);
if (editElem.children("#" + id).length>0) {
editElem = editElem.children("#" + id);
}
editElem.blur(function () {
$(this).css({
'outline': '5px auto -webkit-focus-ring-color',
'border-color': 'rgba(82, 168, 236, 0.8)'
});
$(this).css({
'outline': 'none',
'border-color': '#ccc'
});
}).focus(function () {
$(this).css({
'outline': 'none',
'border-color': 'rgba(255, 0, 0, 0.8)'
});
});
editElem.focus();
}
- 第二种写法
var focusChangeBorder = function ( id ) {
//var elem = $( "input#" + id );
//if (elem.length <= 0) {
// elem = $("#" + id);
//}
var elem = $( "input,select,option,textarea" ).filter( '#' + id );
elem.blur( function () {
elem.focus( function () {
$( this ).css( {
'outline': '5px auto -webkit-focus-ring-color',
'border-color': 'rgba(82, 168, 236, 0.8)'
} );
} );
$( this ).css( {
'outline': 'none',
'border-color': '#ccc'
} );
} ).focus( function () {
$( this ).css( {
'outline': 'none',
'border-color': 'rgba(255, 0, 0, 0.8)'
} );
} );
elem.focus();
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。