(비록 jQuery의 기능을 여전히 배우고 있지만) 간단한 작업처럼 보입니다. 여기 jQuery - 정렬되지 않은 목록에 목록 항목을 동적으로 추가하려면 어떻게해야합니까?
내 HTML입니다 : 여기<div id="fbsignup">
<div class="message messageerror">
<strong>There were errors with your registration:</strong>
<ul></ul>
</div>
</div>
내 (시도) jQuery의 :
// Check Required Fields.
$('#fbsignup input.required').each(function() {
if ($(this).val().trim() == '') {
$(this).next('em').html('*').show();
$('#fbsignup .message ul').add('li').html('Fields marked with * are required.');
}
});
그리고이는 DOM을하고있는 것입니다 :
<div class="message messageerror">
<strong>There were errors with your registration:</strong>
<ul>Fields marked with * are required.</ul>
</div>
그것은을 추가하는 것 내부 html로 텍스트. 나는 그것이 내가 설정 한 것의 내부 html로 <li>
요소를 추가하기를 원한다. 나는 이것이 어떻게 연쇄 작용을한다고 생각 했는가? 나는 또한이 시도
<div class="message messageerror">
<strong>There were errors with your registration:</strong>
<ul>
<li>Fields marked with * are required.</li>
</ul>
</div>
: 절대적으로 아무것도하지 않는
$('#fbsignup .message ul').add('<li>Fields marked with * are required.</li>');
이
내가 함께 결국 원하는 되는 HTML입니다.내가 무엇이 누락 되었습니까? .add
기능이 여기에서 사용할 올바른 것이 아닙니까?
좋아. 선택자 (.html)에 연결할 수 있기 때문에 선택자가 더 좋다. . 감사 – RPM1984