日期:2014-05-20  浏览次数:20696 次

JQury 中如何对增加的div中值的判断
我在div中增加了一个验证两次输入密码是否一样的div,但是当我输入一样的密码时总是显示密码为空?请问我应该怎么处理?
function cheaks(){
var psd1 = $("paramValuepwd1").val();
var psd2 = $("paramValuepwd2").val();

if(psd1==null){
alert("两次密码为null");
$("paramValuepwd1").val("");
$("paramValuepwd2").val("");
return false;
}
if($.trim(psd1)==""||$.trim(psd2)==""){
alert("两次密码为”“");
$("paramValuepwd1").val("");
$("paramValuepwd2").val("");
return false;
}
if(psd1psd1!=psd2){
alert("两次密码不一致");
$("paramValuepwd1").val("");
$("paramValuepwd2").val("");
return false;
}

return true;
}

function chanType(){
//var typeValue = $("#Type").val();

$("#Type").after("<div id='valueTypepsw'>密码:<input type='password' name='paramValue' id ='paramValuepwd1'> 再次输入:<input type='password' name ='paramValue1' id = 'paramValuepwd2' onblur='return cheaks()'></div>");

}

------解决方案--------------------
你的alert("两次密码为”“");得转义

改成下面的这样: alert("两次密码为\"\"");

运行下面的试试:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script language="javascript" type="text/javascript" src="jquery-1.4.2.min.js"></script>

</head>
<body>

<div id='valueTypepsw'>
密码:<input type='password' name='paramValue' id ='paramValuepwd1'> 再次输
入:<input type='password' name ='paramValue1' id = 'paramValuepwd2' onblur='return cheaks()'>
</div> 

<style type="text/css">
  
</style>
<script language="javascript" type="text/javascript">
  

function cheaks(){

var psd1 = $("#paramValuepwd1").val();

var psd2 = $("#paramValuepwd2").val();


if(psd1==null){
alert("两次密码为null");
$("#paramValuepwd1").val("");
$("#paramValuepwd2").val("");
return false;
}
if($.trim(psd1)==""||$.trim(psd2)==""){
alert("两次密码为\"\"");
$("#paramValuepwd1").val("");
$("#paramValuepwd2").val("");
return false;
}
if(psd1!=psd2){
alert("两次密码不一致");
$("#paramValuepwd1").val("");
$("#paramValuepwd2").val("");
return false;
}

return true;
}

function chanType(){

}
</script>
</body>
</html>