在jquery中,根据下拉列表值验证文本框值0或大于0
这里我使用jquery验证插件。在我的表单中,有一个下拉选择和一个输入文本框。当我选择下拉值0时,文本框应为accept大于0,否则必须通过错误。若我选择下拉值1或2,那个么文本框应该只接受0,不超过0,必须通过错误。这是我的要求。请帮忙在jquery中,根据下拉列表值验证文本框值0或大于0,jquery,validation,plugins,Jquery,Validation,Plugins,这里我使用jquery验证插件。在我的表单中,有一个下拉选择和一个输入文本框。当我选择下拉值0时,文本框应为accept大于0,否则必须通过错误。若我选择下拉值1或2,那个么文本框应该只接受0,不超过0,必须通过错误。这是我的要求。请帮忙 参考:您必须为文本框添加自定义验证规则。它检查复选框值和下拉列表值 在表单验证中 textbox: { required: true, custom_rule : true } 然后 您必须为文本框添加自定义验证规则。它
参考:您必须为文本框添加自定义验证规则。它检查复选框值和下拉列表值 在表单验证中
textbox: {
required: true,
custom_rule : true
}
然后
您必须为文本框添加自定义验证规则。它检查复选框值和下拉列表值 在表单验证中
textbox: {
required: true,
custom_rule : true
}
然后
以防万一有人被扔到这个岗位上。kanishka的帖子也解决了我的问题,但我也需要一条自定义消息,具体取决于值。因此,需要做的是: 在表单验证中:
rules: {
textbox: {
required: true,
custom_rule : true
}
}, messages {
textbox: {
required: mymessageprocessor //this is a function that returns custom messages
}
然后在末尾添加以下javascript:
$.validator.addMethod("custom_rule", function(value, element) {
var dropdown_val = $("#dropdown").val();
if((dropdown_val==0 && value>0) || (dropdown_val==1 || dropdown_val==2 ) && value==0))
{
return true;
}
else
{
return false;
}
}, "");
function mymessageprocessor() {
var dropdown_val = $("#dropdown").val();
if (dropdown_val == 0) {
return "value is zero";
} else {
return "value is greater than zero";
}
以防万一有人被扔到这个岗位上。kanishka的帖子也解决了我的问题,但我也需要一条自定义消息,具体取决于值。因此,需要做的是: 在表单验证中:
rules: {
textbox: {
required: true,
custom_rule : true
}
}, messages {
textbox: {
required: mymessageprocessor //this is a function that returns custom messages
}
然后在末尾添加以下javascript:
$.validator.addMethod("custom_rule", function(value, element) {
var dropdown_val = $("#dropdown").val();
if((dropdown_val==0 && value>0) || (dropdown_val==1 || dropdown_val==2 ) && value==0))
{
return true;
}
else
{
return false;
}
}, "");
function mymessageprocessor() {
var dropdown_val = $("#dropdown").val();
if (dropdown_val == 0) {
return "value is zero";
} else {
return "value is greater than zero";
}
你试过什么?我可以在您共享的JSFIDLE中找到任何js脚本。那么您尝试了什么?我可以在您共享的JSFIDLE中找到任何js脚本。这段代码对我来说几乎没有问题。问题是我需要根据值显示这些错误消息。你能帮助我吗?谢谢你的支持。这个代码对我来说几乎没问题。问题是我需要根据值显示这些错误消息。你能帮助我吗?谢谢你的支持