简体   繁体   English

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

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

I need to enter-in a password (without typing on keyboard) by clicking on image(s) on my html page with onclick function or any other action. 我需要使用onclick功能或任何其他操作通过单击html页面上的图像来输入密码(无需在键盘上输入)。 How can I do this? 我怎样才能做到这一点? I tried the code below, which worked for plain text by didn't work for my password-type entry (as seen below). 我尝试了下面的代码,该代码不适用于我的密码类型输入(如下所示),无法用于纯文本。 Can someone pls help me? 有人可以帮我吗?

Here are my codes: 这是我的代码:

<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>

This is the result: 结果如下:

you will notice that nothing showed on the password field. 您会注意到密码字段上没有任何显示。 Please can someone help? 请有人帮忙吗? I will appreciate it.. 我将不胜感激..

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

Use value for input elements like, 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.

相关问题 如何通过使用onclick单击将图像更改为其他图像? - How do i change an image into a different image by clicking on it with onclick? Javascript,图片点击(功能,onclick) - Javascript, image clicking (function, onclick) 如何重复onClick文本输入功能? - How do I repeat the onClick text input function? 如何将图像对象传递给为其分配的onclick函数? - How do I pass the image object into the onclick function being assigned to it? 如何在“图像”类型的输入上调用onclick函数? - How to call an onclick function on an input of type “image”? 我点击一个输入收音机并通过再次点击更改图像src ...如何更改图像的样式? - I click an input radio and change an image src, by clicking again…how do I change the image back how it was? (飞镖)我希望触发两个不同的onclick函数,具体取决于单击时是否选中了单选按钮。 我怎么做? - (dart) I want two different onclick function to trigger depending if the radio button is checked or not upon clicking. How do I do that? 如何通过单击图像打开文本? - How Do I Open Text by Clicking on An Image? 我如何在图片地图上onclick提交功能 - how will i onclick submit function on image map 如何替换画布onclick上的图像? - How do I replace an image on a canvas onclick?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM