2013-08-30 2 views
0

javascript onclick 함수를 암호 필드에 지속적으로 입력하여 암호 값을 입력 할 수 있습니까?onclick 함수를 사용하여 JavaScript 값을 암호 입력에 계속 입력 하시겠습니까?

나는 onclick 기능과 함께 작동하는 두 개의 'Blue'및 'Red'이미지를 가지고 있으며 아래 값을 가지고 있습니다.

Blue= w3! 
Red= T4. 

나는 그것이 값 입력 블루 이미지를 클릭

'W3를!' 암호 필드에 입력하십시오. 그런 다음 Red 이미지를 클릭하면 입력이 대체되고 암호 필드에서 'T4'가됩니다. 빨간색 입력을 파란색으로 연결하면 암호 대신 'w3! T4'가됩니다. Pls 여기 내가 도움이 필요해. 다음은 내 코드 항목은 다음과 같습니다

<!DOCTYPE html> 
<html> 
<head> 
<style>  
# red 
{width:50px; 
    height:50px; 
    } 
# blue 
{width:50px; 
    height:50px; 
    } 
</style> 

<script src="javascript/myred.js"></script> 
<script src="javascript/myblue.js"></script> 
</head> 

<body> 

<img id="red" src="images/items/blue_in.jpg" alt="no blue" onclick="myblue()"> 
<img id="blue" src="images/items/red_in.jpg" alt="no red" onclick="myred()"> 

<label for="password">Passcode:</label> 
<input name="password" type="password" id="password"> 

</body> 
</html> 
내 서버에 저장

내 자바 스크립트 파일은 아래에 볼 수 있습니다; myblue를 들어

:

function myblue() 
    { 
    x=document.getElementById("password"); // Find the element 
    x.value="w3!"; // add the content 
    } 

myred를 들면 : 나는 적색 입력 ... 환호를 교체하지 않고 암호 필드에 파란색 이미지의 값을 추가하는 방법

function myred() 
    { 
    x=document.getElementById("password"); // Find the element 
    x.value="T4"; // add the content 
    } 

하시기 바랍니다. . 의견은 환영합니다 ..

+2

제작시 일부 bruteforce 웹 도구를 감지합니까? –

+0

실제로는 아니지만 유사점에 대한 연구를하고 있습니다 ... –

+1

jquery 코드가 없으며 일반적인 Javascript가 태그를 제거했습니다. – Barmar

답변

2

사용 +=

function myblue() 
    { 
    x=document.getElementById("password"); // Find the element 
    x.value += "w3!"; // add the content 
    } 

function myred() 
    { 
    x=document.getElementById("password"); // Find the element 
    x.value += "T4"; // add the content 
    } 
을 솔루션은 물론, 그것은 될 수 meanining 문자열 추가
+0

코드가 완벽하게 작동했습니다 ... cheers –

1
function myblue() 
{ 
    x=document.getElementById("password"); // Find the element 
    x.value += "w3!"; // add the content 
} 

"W3을! W3! W3! T4!" 클릭 빈도에 따라 다릅니다.

function myblue() 
{ 
    x=document.getElementById("password"); // Find the element 
    if(x.value.indexOf('w3!') < 0){ 
    x.value += "w3!"; // add the content 
    } 
} 

값을 한 번만 입력하려는 경우이 방법을 사용하십시오. 물론이 함수를 다음과 같이 변경해야합니다. myred()

+0

감사합니다 ... 완벽하게 ... 감사합니다! –

+1

그러면 올바른 대답 중 하나를 표시하는 것이 어떻습니까? – Soundz

+0

알림을 보내 주셔서 감사합니다 ... :) –

관련 문제