我想使用 jQuery/js 执行以下操作:
- 获取表单输入标签的值
- 将这些标签作为输入本身的值
- 隐藏标签
很简单。因为我不想打字
$('firstname input').val('First Name');
$('lastname input').val('Last Name');
$('street input').val('Street');
$('city input').val('City');
等等,我怎样才能从每个元素中提取标签并将其粘贴到该元素的输入框中?
这是 HTML 的略微缩写版本:
<form action="/" method="post" id="user-register-form" accept-charset="UTF-8">
<div>
<div id="customreg">
<div class="firstname">
<div class="form-item form-type-textfield form-item-first-name">
<label for="edit-first-name">
First Name
<span class="form-required" title="This field is required.">*</span> </label>
<input type="text" id="edit-first-name" name="first_name" value="" size="24" maxlength="128" class="form-text required" />
</div>
</div>
<div class="lastname">
<div class="form-item form-type-textfield form-item-last-name">
<label for="edit-last-name">
Last Name
<span class="form-required" title="This field is required.">*</span>
</label>
<input type="text" id="edit-last-name" name="last_name" value="" size="24" maxlength="128" class="form-text required" />
</div>
</div>
</div>
<input type="submit" id="edit-submit--3" name="op" value="Join!" class="form-submit" />
<input type="hidden" name="form_build_id" value="form-5DDdSC4UFk_YPJIfuJgMhC4215CYJneg9PBDdetJtDQ" />
<input type="hidden" name="form_id" value="custreg_user_register_form" />
</div>
</form>