![](/img/trans.png)
[英]How do i change an image into a different image by clicking on it with 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.