-6

我有这个javascript代码。但是代码没有得到输入的值,我在这里做错了什么?

<script type="text/javascript">
function myFunc() {
    "use strict";
    var un = document.getElementByID('user').value;
    var pw = document.getElementByID('pass').value;
    var x  ;
    if(un=="abc") {
        if(pw=="123") {
            document.getElementById('validate').innerHTML ="validation sucessful";
        }
        else {
            document.getElementById('validate').innerHTML ="validation unsuccessful";
        }
    }
    else {
        document.getElementById('validate').innerHTML ="invalid username";
    }
}
</script>
<p>Click on the button to login</p>

USERNAME : <input type='text'   id='user'   value="  "   /><!-- Should be like type="text" and not type="  text"-->
PASSWORD:   <input type='password'    id='pass'   />  <!-- Should be like type="password" and not type="  password"-->
<p id='validate'></p>
<input type='button'  onclick="myFunc()" value='Login' />
4

2 回答 2

1

函数名不正确getElementByID,使用这个:

var un = document.getElementById('user').value;
var pw = document.getElementById('pass').value;
于 2012-09-20T14:23:19.493 回答
1

document.getElementById不是document.getElementByIDjavascript 是Javascript 区分大小写

var un = document.getElementById('user').value;
var pw = document.getElementById('pass').value;

不是

var un = document.getElementByID('user').value;
var pw = document.getElementByID('pass').value;
于 2012-09-20T14:24:00.757 回答