Jam's story
[JQuery] 제이쿼리 객체에 함수 추가 하고 사용 본문
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>2022.06.14 11:16:53</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<h3>ex10.html 제이쿼리 객체에 함수 추가 하고 사용</h3>
<p>Lorem ipsum dolor sit amet.</p>
<script>
// $("p").myAlert("경고창을 띄웁니다.");//myAlert함수가 제이쿼리에 없다.
//제이쿼리 객체에 myAlert추가 하고 사용
</script>
<script>
//객체 생성자에 함수 추가
jQuery.prototype.myAlert=function(msg){
// jQuery.prototype.myAlert=function(msg) == jQuery.fn.myAlert=function(msg)
alert("msg");
}
$("p").myAlert("경고창을 띄웁니다.");
</script>
</body>
</html>
'WEB > JQuery' 카테고리의 다른 글
[JQuery] map() get() (0) | 2022.06.14 |
---|---|
[JQuery] 입력값에 대한 유효성 검사하고 막기 (0) | 2022.06.14 |
[jQuery] addClass(function(index, currentClassName) (0) | 2022.06.14 |
[JQuery] jQuery.each() - 배열을 인자값으로 (0) | 2022.06.14 |
[JQuery] 남은시간 계산하여 표시 (0) | 2022.06.14 |
Comments