Dko*_*ong 0 javascript validation
我有用户名和密码文本框.我希望它们都显示默认文本,即"用户名"和"密码",但是当用户点击密码框时,出于安全原因,它应该动态地更改为"密码"类型.
我已经设法用javascript代码轻松地做到这一点,但它不想在IE中工作.
<input id="username" class="username" name="u" type="text" value="username" onclick="if(this.value='username') {this.value=''};" />
<input id="password" class="password" name="p" type="text" value="password" onclick="if(this.value='password') {this.value=''; this.type='password'};" />
Run Code Online (Sandbox Code Playgroud)
假设您的HTML代码是这样的
<input type="text" id="txtId" />
Run Code Online (Sandbox Code Playgroud)
您可以使用Jquery替换它,
$('#txtId').replaceWith('<input type="password" id="txtId" />')
Run Code Online (Sandbox Code Playgroud)