jquery - 通过类而不是元素名称将元素值传递给 jQuery.validator.addMethod
问题描述
我添加了一个方法验证插件。但是我需要使用类名来传递元素,而不是传递名称,因为我不知道id
页面上呈现的元素的名称。
我尝试了创建方法并尝试使用addClassRules
. params[1]
问题是价值没有进来undefined
。
我无法弄清楚如何将元素值传递给方法。
jQuery.validator.addMethod("MyMethod", function(value, element, params) {
alert("First Value is " + params[0]);
alert("Second Value is " + params[1]);
return true; //for now
//My code to do validation
}, '{0}'); //error message will come from params[0]
jQuery.validator.addClassRules("MyClassName", {
required: true,
MyMethod: ['My error message', $('#secCommonInformation .DOB').val()]
});
解决方案
推荐阅读
- java - 优化没有为 Java SDK 代码激活
- python - 如何在 Python tkinter 中获取入口值?
- r - 获取基本地图而不是通过数据指定的地图
- android - 如何使用 Espresso 长按 RecyclerView 中的项目
- c - 在C中为结构的二维数组元素赋值
- python - 如何使用 Kivy 将 TextInput 转换为地图视图的浮点数
- ios - 如何修复不为 iOS 构建的 React Native App
- angular - Angular - 如何通过选择器将事件绑定到 HTML 元素?
- python - 在 Tkinter 中更新文本小部件中的值
- reporting-services - 用于从 oracle 数据库中过滤数据集时,多值参数不起作用