0

我正在寻找有关如何使用 Qunit 框架编写单元测试用例以进行不引人注目的 javascript 客户端验证的参考:

   jQuery.validator.addMethod('requiredifnotempty',
   function(value, element, parameters) {
   var otherPropertyId = '#' + parameters['otherproperty'];

// get the actual value of the other control
var otherControl = $(otherPropertyId);
var controlType = otherControl.prop('type');
var otherValue = otherControl.val();

if (controlType === 'checkbox') {
    otherValue = otherControl.prop("checked").toString();
}

if (otherValue.trim().length > 0) {
    return $.validator.methods.required.call(this, value, element, parameters);
}

return true;
}

 );
jQuery.validator.unobtrusive.adapters.add(
'requiredifnotempty',
 ['otherproperty'],
 function (options) {
    options.rules['requiredifnotempty'] = {
    otherproperty: options.params['otherproperty']
  };
   options.messages['requiredifnotempty'] = options.message;        
 });
4

1 回答 1

-1

以下是一些参考资料:

于 2013-10-11T05:36:16.247 回答