P

jQuery w3schools 한글판 강좌47 -A Callback Function for text(), html(), and val()

· 2017-03-27 (월) 22:55:42 · 1873

jQuery w3schools 한글판 강좌47 - text(), html(), val() 에 대한 콜백함수 

 

이전에 소개된 3개 메소드들(text(), html(), val()) 모두 역시 콜백 함수를 가집니다.

콜백함수는 아래의 두개의 매개변수를 가집니다:

1. 선택된 요소 리스트에서 현재 요소의 인덱스

2. 원래(구)값

 

따라서 여러분은 그 함수로부터의 새 값으로 사용하고 싶은 문자열을 리턴하십시오.

 

다음 예는 콜백함수를 가지는  text(), html() 메소드를 보여줍니다:

Example

 

$("#btn1").click(function(){
    $("#test1").text(function(i, origText){
        return "Old text: " + origText + " New text: Hello world!
        (index: "
 + i + ")"
    });
});

$("#btn2").click(function(){
    $("#test2").html(function(i, origText){
        return "Old html: " + origText + " New html: Hello <b>world!</b>
        (index: "
 + i + ")"
    });
}); 

|
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,403건

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
PHP 17-04-04 조회 2,361
PHP 17-04-04 조회 2,863
jQuery 17-04-03 조회 1,777
jQuery 17-04-03 조회 2,298
jQuery 17-04-03 조회 1,859
node.js 17-03-29 조회 3,888
jQuery 17-03-29 조회 2,181
jQuery 17-03-29 조회 2,136
jQuery 17-03-29 조회 2,039
jQuery 17-03-28 조회 2,090
jQuery 17-03-28 조회 2,480
PHP 17-03-28 조회 2,301
PHP 17-03-28 조회 1,909
PHP 17-03-28 조회 2,106
jQuery 17-03-27 조회 3,212
jQuery 17-03-27 조회 1,874
jQuery 17-03-27 조회 1,773
jQuery 17-03-26 조회 2,137
jQuery 17-03-26 조회 2,095
jQuery 17-03-26 조회 2,272
jQuery 17-03-23 조회 2,066
jQuery 17-03-23 조회 2,026
jQuery 17-03-23 조회 2,015
jQuery 17-03-22 조회 2,080
jQuery 17-03-22 조회 2,300
jQuery 17-03-22 조회 1,945
jQuery 17-03-20 조회 2,127
jQuery 17-03-20 조회 2,389
jQuery 17-03-20 조회 1,953
jQuery 17-03-18 조회 2,274