用JS添加聚焦事件,以给父元素添加边框阴影为例

function setBoxShadow (){
	$('.class').each(function () {
		$(this).focus(function(){
			$(this).parent().css("outline","none");/*禁用浏览器自带边框阴影*/
			$(this).parent().css("box-shadow","0px 0px 15px 1.5px #95B8E7");
		});
		$(this).blur(function(){
			$(this).parent().css("box-shadow","none");
		});
	});
}

这段代码给我们选中的元素都添加了聚焦和失焦事件,

聚焦时给父元素添加边框阴影,失焦时去除阴影。

猜你喜欢

转载自blog.csdn.net/lightpass/article/details/81772435