![](/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.