我想实现如下功能:
在登录表单的密码框中,默认显示”请输入密码“,当用户点击密码框时,”请输入密码“消失,并且这个input域的type=‘password’(默认是text)。
由于input的type属性不能修改,所以克隆了一个对象修改后添加进去,然后删除原对象。代码如下,但是点击不能输入东西!求解!$(function(){
$('input[name=paswd]').focus(function(){
var newPasw=$(this).clone(true).attr({
value:'',
type:'password'
});
$(this).replaceWith(newPasw);
});
});<table>
<form method="post" action="#">
<tr>
<td>用户名:</td>
<td><input type="text" name="userName" value="请输入用户名"></td>
</tr>
<tr>
<td>密码:</td>
<td id='ppp'><input name="paswd" type="text" value="请输入密码"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="登录"></td>
</tr>
</form>
</table>