繁体   English   中英

如何使用onclick功能点击图片输入密码?

[英]How do I input password by clicking image with onclick function?

我需要使用onclick功能或任何其他操作通过单击html页面上的图像来输入密码(无需在键盘上输入)。 我怎样才能做到这一点? 我尝试了下面的代码,该代码不适用于我的密码类型输入(如下所示),无法用于纯文本。 有人可以帮我吗?

这是我的代码:

<form style=" margin-left:200px; font-weight:600">
     <fieldset>
     <legend>STEP II:</legend>
     <input id="psx2" type="password"> 
     <p id="psx3">all the way</p> 
     <p id="psx4">the ramp flies</p> 

     <script>
     function myFunction()
     {
 x=document.getElementById("psx2");  // Find the element
     x.innerHTML="12345";    // Change the content

     x=document.getElementById("psx3");  // Find the element
     x.innerHTML="Hello!";    // Change the content

     x=document.getElementById("psx4");  // Find the element
     x.innerHTML="Hey!";     // Change the content
     }
     </script>

     <a href="#"> 
     <img src="images/colourimages/red.jpg" 
     alt="red not"
     onclick="myFunction()" 
     width="50" 
     height="50" 
     id="red" />
     </a>

     </fieldset>
     </form>

结果如下:

您会注意到密码字段上没有任何显示。 请有人帮忙吗? 我将不胜感激..

表单元素不使用.innerHTML来更改需要使用.value的内容

value用于input elements例如,

function myFunction()
{
   x=document.getElementById("psx2");  //  Input element
   x.value="12345";    // Change the content

   // innerHTMl is fine for p or div tags
   ....... 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM