다음 작업을 수행하려면 어떻게 해야 합니까?
document.all.regTitle.innerHTML = 'Hello World';
jQuery 사용처regTitle
나의div
아이디?
질문에 대한 답변
$("#regTitle").html("Hello World");
html() 함수는 HTML의 문자열을 사용할 수 있으며, 이 함수는 html을 효과적으로 변경할 수 있습니다..innerHTML
소유물.
$('#regTitle').html('Hello World');
단, text() 함수는 지정된 요소의 (텍스트) 값을 변경하지만,html
구조.
$('#regTitle').text('Hello world');
기존 내용 대신 렌더링할 jQuery 개체가 있는 경우:그러면 내용을 재설정하고 새 내용을 추가합니다.
var itemtoReplaceContentOf = $('#regTitle'); itemtoReplaceContentOf.html(''); newcontent.appendTo(itemtoReplaceContentOf);
또는 다음 중 하나를 선택합니다.
$('#regTitle').empty().append(newcontent);
답변은 다음과 같습니다.
//This is the setter of the innerHTML property in jQuery $('#regTitle').html('Hello World');
//This is the getter of the innerHTML property in jQuery var helloWorld = $('#regTitle').html();
요소의 내부 HTML을 변경하는 방법을 알려주는 답변이 이미 있습니다.
단, HTML을 바꾸려면 Fade Out/Fade In과 같은 애니메이션을 사용하는 것이 좋습니다.HTML을 바꾸면 내부 HTML을 즉시 변경할 수 있습니다.
애니메이션을 사용하여 내부 HTML 변경
$('#regTitle').fadeOut(500, function() {
$(this).html('Hello World!').fadeIn(500); });
이것이 필요한 함수가 많으면 내부 HTML을 변경하는 공통 함수를 호출할 수 있습니다.
function changeInnerHtml(elementPath, newText){
$(elementPath).fadeOut(500, function() {
$(this).html(newText).fadeIn(500);
}); }