在将文本附加到特定标签时出现一些问题
这是我的html代码
<label for="password">
Password <small>required</small>
<input type="password" name="password" placeholder="Enter password" required pattern="[a-zA-Z]+"/>
<small class="error">Password is required</small>
<small class="server-error"></small>
</label>现在,当我的服务器验证通过消息返回false时,我想将该消息附加到<small class="server-error"></small>中
下面是我的ajax部分
$.post('./login.php', $(this).serialize(), function(msg){
// working = false;
// $('#submit').val('Login');
if(msg.status){
window.location.href = "testt.php";
}
else {
$.each(msg.errors,function(k,v){
/// NOT SURE WHAT TO HAVE HERE TO GET THE SPECIFIC LABEL
});
//$('#testForm').html("fail");
}
}, 'json');发布于 2014-07-08 17:31:59
$.each(msg.errors,function(k,v){
$("label[for=" + k +"]").find(".server-error").append("<br>" + v);
}); 此代码将在其各自的错误div中显示列的错误。
https://stackoverflow.com/questions/24628256
复制相似问题