본문 바로가기

프로그래밍/jQuery

클릭했을 때 색 채움, 마우스 커서(focus,blur)

 

클릭시 노랑, mouseover시 레드

<!-- 테그명으로 접근 -->

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<title>Insert title here</title>
</head>
<body>

이름:<input type="text"><br><br>

이메일:<input type="text"><br><br>

<p>여기가 p tag 1입니다</p>

<p>여기가 p tag 2입니다</p>
<br>

<script type="text/javascript">
$(document).ready(function(){
	
	$("input").focus(function () {  //클릭했을 때 focus
		$(this).css("background-color","#ffff00"); //노랑
	});
	
	$("input").blur(function(){     //벗어났을때
		$(this).css("background-color","#fff"); //화이트
	});
	
	$("p").mouseover(function () {   //마우스 커서가 위에 도달햇을때
		$(this).css("background-color","#ff0000"); //레드
	});
	
	$("p").mouseout(function () {   //마우스 커서가 벗어났을 때
		$(this).css("background-color","#fff"); //화이트
	});
	
	$("p").dblclick(function(){     //더블 클릭 할 때
		alert($(this).text());	    //text값을 받아온다 getter역할
	});

});


</script>


</body>
</html>