在此标记中,我需要将标签文本“电子邮件”替换为“用户名”。我只能通过 jQuery 访问。
<div class="foo" style="border:1px solid #444">
<span class="field-with-fancyplaceholder">
<label class="placeholder" for="pseudonym_session_unique_id" style="font-size: 13px;">
<span>Email</span>
</label>
<input id="pseudonym_session_unique_id" class="text" type="text" size="30" name="pseudonym_session[unique_id]">
</span>
<span class="field-with-fancyplaceholder">
<label class="placeholder" for="pseudonym_session_password" style="font-size: 13px;">
<span>Password</span>
</label>
<input id="pseudonym_session_password" class="text" type="password" size="30" name="pseudonym_session[password]">
</span>
</div>
当我尝试这个
$('label:nth-of-type(1)').addClass('bar');
$('.bar span').text('user name');
// because $('label:nth-of-type(1) span') doesn't work
两个标签都被选中,两个跨度都说“用户名”。我怎样才能得到第一个?