Javascript Jquery需要在下一个最近的类中显示错误消息,具体取决于输入

Javascript Jquery需要在下一个最近的类中显示错误消息,具体取决于输入,javascript,jquery,Javascript,Jquery,下面是一个例子 有多个输入表单。每个输入表单旁边都有span和class=“numeric” 但在所有class=“errmsg”中显示错误消息。如何仅在下一个最近的位置显示?使用以下方法: $(this).next(".errmsg").html("hmm"); $(“.numeric”).按键(功能(e){ //如果字母不是数字,则显示错误,不键入任何内容 如果(e.which!=8&&e.which!=0&&e.which57)){ //显示错误消息 //$(“.errmsg”).ht

下面是一个例子

有多个输入表单。每个输入表单旁边都有
span
class=“numeric”

但在所有
class=“errmsg”
中显示错误消息。如何仅在下一个最近的位置显示?

使用以下方法:

$(this).next(".errmsg").html("hmm");
$(“.numeric”).按键(功能(e){
//如果字母不是数字,则显示错误,不键入任何内容
如果(e.which!=8&&e.which!=0&&e.which<48 | e.which>57)){
//显示错误消息
//$(“.errmsg”).html(“仅限数字”).show().fadeOut(“慢”);
$(this.next(“.errmsg”).html(“hmm”);
//警报(“仅限数字”);
返回false;
}
});

每加仑英里*:

里程*:
使用以下方法:

$(this).next(".errmsg").html("hmm");
$(“.numeric”).按键(功能(e){
//如果字母不是数字,则显示错误,不键入任何内容
如果(e.which!=8&&e.which!=0&&e.which<48 | e.which>57)){
//显示错误消息
//$(“.errmsg”).html(“仅限数字”).show().fadeOut(“慢”);
$(this.next(“.errmsg”).html(“hmm”);
//警报(“仅限数字”);
返回false;
}
});

每加仑英里*:

里程*:
使用以下方法:

$(this).next(".errmsg").html("hmm");
$(“.numeric”).按键(功能(e){
//如果字母不是数字,则显示错误,不键入任何内容
如果(e.which!=8&&e.which!=0&&e.which<48 | e.which>57)){
//显示错误消息
//$(“.errmsg”).html(“仅限数字”).show().fadeOut(“慢”);
$(this.next(“.errmsg”).html(“hmm”);
//警报(“仅限数字”);
返回false;
}
});

每加仑英里*:

里程*:
使用以下方法:

$(this).next(".errmsg").html("hmm");
$(“.numeric”).按键(功能(e){
//如果字母不是数字,则显示错误,不键入任何内容
如果(e.which!=8&&e.which!=0&&e.which<48 | e.which>57)){
//显示错误消息
//$(“.errmsg”).html(“仅限数字”).show().fadeOut(“慢”);
$(this.next(“.errmsg”).html(“hmm”);
//警报(“仅限数字”);
返回false;
}
});

每加仑英里*:

里程*:

我只是做了如下更改

$(this).siblings(".errmsg").html("hmm"); 
to 
$(this).next(".errmsg").html("hmm");

看看这个。

我只是做了如下更改

$(this).siblings(".errmsg").html("hmm"); 
to 
$(this).next(".errmsg").html("hmm");

看看这个。

我只是做了如下更改

$(this).siblings(".errmsg").html("hmm"); 
to 
$(this).next(".errmsg").html("hmm");

看看这个。

我只是做了如下更改

$(this).siblings(".errmsg").html("hmm"); 
to 
$(this).next(".errmsg").html("hmm");
看看这个