0

それが問題です。

私の頭:

<script  language="JavaScript">
    function checkIt(){
        var pass = document.form1.value;  
        if (pass == "1234")  
            {  
                alert("Please input a Value");  
                return false;  
            }  
        else   
            {  
                alert('Code has accepted : you can try another');  
                return true;   
            }  
    } 
window.onload = checkIt();
</script>

私の体:

<form action="#" method="post" id="form1" onsubmit="checkIt();">
    <input type="password" id="sn" name="sn" placeholder="Enter Your Password">
<img src="ok.gif" onclick="submit();" style="cursor: pointer;">
</form>

誰が私が間違っているのか教えてもらえますか? 機能していません。入力された sn という名前の値を var pass と比較できるようにする必要があります。

私は初心者であり、ネイティブ スピーカーではないので、落ち着いてください:)

4

5 に答える 5

0

以下を試してください:

Javascript

<script  language="JavaScript">
    function checkIt(){
        var pass = document.getElementById("sn").value;  
        if (pass == "1234")  
            {  
                alert("Please input a Value");  
                return false;  
            }  
        else   
            {  
                alert('Code has accepted : you can try another');  
                return true;   
            }  
    } 
</script>

HTML

<form action="#" method="post" id="form1" onsubmit="return checkIt();">
    <input type="password" id="sn" name="sn" placeholder="Enter Your Password">
    <img src="ok.gif" onclick="document.getElementById("form1").submit();" style="cursor: pointer;">
</form>
于 2013-06-04T16:59:10.327 に答える
0

試すvar pass = document.getElementById('sn').value;

于 2013-06-04T16:41:39.517 に答える