/**
 * Bug绕过去方案WorkAround
 * Bug描述:
 * JQuery的Validation的和form的input元素设为readonly,一对不可调和的矛盾:
 * 一个设置为required的input元素,永久设置为readonly,表单提交时,如果该字段值为空,
 * Validation功能就不能正常工作;反之,如果不设置readonly,又没法限制用户胡乱粘贴非法数据。
 * http://stackoverflow.com/questions/26838839/how-can-i-enable-jquery-validation-on-readonly-fields
 * para elementId : 元素名称
 */
function resolvedValidationConflictWithReadonly(elementId){
    $(document).on("focusin", elementId, function() {
        $(this).prop('readonly', true);
    });

    $(document).on("focusout", elementId, function() {
       $(this).prop('readonly', false);
    });
}
/**
 * 用于弹框上
 * @param elementId
 */
function resolvedValidationConflictWithReadonlyParent(elementId){
    //不能改成document
    $parent("body").on("focusin", elementId, function() {
        $(this).prop('readonly', true);
    });

    $parent("body").on("focusout", elementId, function() {
       $(this).prop('readonly', false);
    });
}

 

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2021-11-03
  • 2022-01-27
  • 2022-12-23
  • 2021-07-30
  • 2021-11-04
猜你喜欢
  • 2021-12-01
  • 2022-12-23
  • 2021-09-04
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
相关资源
相似解决方案