下面这段函数在一个密码输入框onkeypress时调用想要在下面一个段落标签内显示出输入的密码来,并且如果用户按了退格键 ,下面的内容消失function displaykey(e)
//函数用来显示键入进去的密码,供用户确认密码
{
//which key was pressed?
//克服浏览器不兼容问题
if(e.keyCode)
{
keycode=e.keyCode;
}
else
{
keycode=e.which;
}
character=String.fromCharCode(keycode);
//find  the object for the  destination paragraph
k=document.getElementById("showpassword");
//add the character to the  paragraph
if(keycode==8) //输入为退格键的时候   这里的意思是如果用户按了退格键就删除下方一个段落标签中的文字
{
character=""
k.innerHTML=character;
}
k.innerHTML+=character;
}