Javascript Html/JS在模糊/聚焦后在输入中显示密码
我有一个包含密码字段的简单表单:Javascript Html/JS在模糊/聚焦后在输入中显示密码,javascript,html,input,Javascript,Html,Input,我有一个包含密码字段的简单表单: <input required type="password" value="Insert password" style="color:#888;" onfocus="inputFocus(this)" onblur="inputBlur(this)"> 若我加载页面,我希望看到输入字段中的标准值。对于typetype=“text”这不是问题,但是对于type=“password”我只看到点。 我希望看到默认值(插入密码),但当用户开始键入密码
<input required type="password" value="Insert password" style="color:#888;" onfocus="inputFocus(this)" onblur="inputBlur(this)">
若我加载页面,我希望看到输入字段中的标准值。对于typetype=“text”
这不是问题,但是对于type=“password”
我只看到点。
我希望看到默认值(插入密码),但当用户开始键入密码时,他必须看到点
怎么做
感谢您的回复。使用占位符属性:
HTML5占位符怎么样?您不需要JavaScript来实现此目的:
<input required type="password" placeholder="Insert password" style="color:#888;">
答案很简单-不要使用“插入密码”的
值
属性,而是使用占位符
<input type="password" placeholder="insert password">
您是否意识到浏览器内置了此功能?占位符属性。如果要向用户显示其键入的密码,可以使用attr(“type”、“text”);或属性(“类型”、“密码”);但是对于占位符,您应该使用上面的建议
<input type="password" placeholder="insert password">