日期:2014-05-16  浏览次数:20423 次

用checkbox做显示密码功能输入密码前点击,密码框内提示文字消失怎么解决
新手菜鸟求助   代码如下   
在输入密码前  点击checkbox   输入框内的提示文字就消失了    如果不想提示文字消失   怎么改? 

[code=html
<p><label class="control-label" for="inputPassword">密码</label>
  <span id="pass1"><input id="pw1" name="pw1" placeholder="输入密码" type="password" /></span>
 <p style="text-indent:-40px">
  <p><label class="control-label" for="inputPassword">确认密码</label>
 <span id="pass2"><input id="pw2" name="pw2" placeholder="再次输入密码" type="password" /></span>

 <input type="checkbox" name="showpass" onclick=
"var temp1=document.getElementById('pw1').value;
var temp2=document.getElementById('pw2').value;
if(this.checked){
document.getElementById('pass1').innerHTML='<input type=text id=pw1 name=pw1>';
document.getElementById('pass2').innerHTML='<input type=text id=pw2 name=pw2>';
}
else
{
document.getElementById('pass1').innerHTML='<input type=password id=pw1 name=pw1>';
document.getElementById('pass2').innerHTML='<input type=password id=pw2 name=pw2>';

document.getElementById('pw1').value=temp1;
document.getElementById('pw2').value=temp2;
" />显示密码</p>
[/code]
------解决方案--------------------

<html>
<head>
    <title>I Love You!</title>
    <meta charset="utf-8" />
    <script type="text/javascript">
var str1 = "输入密码";
var str2 = "再次输入密码";
        function doclick(){
var span1 = document.getElementById('pass1');
var span2 = document.getElementById('pass2');
var input1 = document.getElementById('pw1');
var input2 = document.getElementById('pw2');

            var temp1 = input1.value==str1 ? "" : input1.value;
var temp2 = input2.value==str2 ? "" : input2.value;
            var checkBox= document.getElementById("chb");

if(checkBox.checked){
input1.type = "text";
input2.type = "text";

        input1.value=temp1 == "" ? str1 : temp1;
            input2.value=temp2 == "" ? str2 : temp2;

fixColor();
            }
            else
            {
input1.type = "password";
input2.type = "password";

input1.value=temp1;
input2.value=temp2;
            }
        }

function fixColor(){
var input1 = document.getElementById('pw1');
var input2 = document.getEl