看起來像一個簡單的事情(雖然即時通訊仍然在學習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。我希望它添加<li>
元素與我設置的內部html - 我認爲這是如何鏈接工程?
這是HTML我想與落得:
<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>');
這也絕對沒有什麼。
我在想什麼? .add
功能在這裏使用不正確嗎?
不錯,我更喜歡這個,因爲你可以鏈接選擇器(.html) 。 謝謝 – RPM1984 2010-08-10 04:59:07