document.getElementById(“ID”)。value not working

我需要你的帮助。我有一个非常简单的问题,我无法弄清楚。它很难解释,但我对一条线有评论,我希望你能理解它。这是我的代码。对于长篇帖子感到抱歉,但我似乎无法摆脱这个漏洞。document.getElementById(“ID”)。value not working

function CheckLength() 

{

var stringpassword = document.getElementById('Pass').value;

alert(document.getElementById('Pass').value); --> this part is only printing a blank.

/*

if(document.getElementById("Pass").value.length > 8)

{

return true;

}

else

{

alert(document.getElementById("Pass").value.length);

return false;

}

*/

}

function Check(a)

{

switch(a)

{

case 1 :

var first = document.getElementById("Uname").value.toUpperCase().indexOf(document.getElementById("Fname").value.toUpperCase());

var last = document.getElementById("Uname").value.toUpperCase().indexOf(document.getElementById("Lname").value.toUpperCase());

if(first !=-1 || last != -1)

{

alert("huy mali ang username. bawal yan pre");

document.getElementById("Uname").value = "";

}

break;

case 2 :

var gate = 0;

var first = document.getElementById("Pass").value.toUpperCase().indexOf(document.getElementById("Fname").value.toUpperCase());

var last = document.getElementById("Pass").value.toUpperCase().indexOf(document.getElementById("Lname").value.toUpperCase());

if(first !=-1 || last != -1)

{

alert("mali dahil sa name");

gate++;

}

if(!CorrectPassword())

{

gate++;

}

if(!CheckLength())

{

gate++;

}

if(gate != 0)

{

alert("Please follow password policy");

document.getElementById("Pass").value="";

}

break;

case 3:

if(document.getElementById("Pass").value != document.getElementById("Rpass").value)

{

document.getElementById("Rpass").value = "";

}

break;

}

}

在身体某处:

<input type="Password" placeholder="Password" value="" id="Pass" onblur="Check(2)"/> 

但是当我尝试它。在密码字段上输入密码后,点击其他一些。警报框只会返回一个空白警报框。即使简单的赋值语句不起作用?原谅我的坏英语

回答:

我得到它的工作......我不得不取出检查checkPassword(),因为你没有提供该功能。

在#Pass元素上,删除onblur属性。我把它分配在我提供的js的底部。

的jsfiddle:http://jsfiddle.net/jeffshaver/vcRDp/1/

function CheckLength() { 

var stringpassword = document.getElementById('Pass').value;

alert(document.getElementById('Pass').value);

/*

if(document.getElementById("Pass").value.length > 8)

{

return true;

}

else

{

alert(document.getElementById("Pass").value.length);

return false;

}

*/

}

function Check(a) {

switch(a) {

case 1 :

var first = document.getElementById("Uname").value.toUpperCase().indexOf(document.getElementById("Fname").value.toUpperCase());

var last = document.getElementById("Uname").value.toUpperCase().indexOf(document.getElementById("Lname").value.toUpperCase());

if(first !=-1 || last != -1) {

alert("huy mali ang username. bawal yan pre");

document.getElementById("Uname").value = "";

}

break;

case 2 :

var gate = 0;

if(first !=-1 || last != -1) {

alert("mali dahil sa name");

gate++;

}

if(!CheckLength()) {

gate++;

}

if(gate != 0) {

alert("Please follow password policy");

document.getElementById("Pass").value="";

}

break;

case 3:

if(document.getElementById("Pass").value != document.getElementById("Rpass").value) {

document.getElementById("Rpass").value = "";

}

break;

}

}

documentgetElementById('Pass').addEventListener('blur', function() { Check(2) }, false);

以上是 document.getElementById(“ID”)。value not working 的全部内容, 来源链接: utcz.com/qa/260976.html

回到顶部