• jQuery插件之清空区域内容


    (function($) {
    $.fn.extend({
    clear:function(){
    cl(this);
    },
    }) ;
    function cl(_id){
    $("input,select,textarea", _id).each(function() {
    var t = this.type, tag = this.tagName.toLowerCase();
    if (t == "text" || t == "hidden" || t == "password"
    || tag == "textarea") {
    this.value = "";
    } else {
    if (t == "file") {
    var _1e = $(this);
    _1e.after(_1e.clone().val(""));
    _1e.remove();
    } else {
    if (t == "checkbox" || t == "radio") {
    this.checked = false;
    } else {
    if (tag == "select") {
    this.selectedIndex = -1;
    }
    }
    }
    }
    });
    };
    })(jQuery);

    $(function(){
    $("#btn").click(function(){
    $("#addForm").clear();
    });
    });

    =====================

    (function ($) {
    $.fn.extend({
    clear: function () {
    cl(this);
    },
    validate: function (messages) {
    $("input,select,textarea", this).each(function () {
    var t = this.type, tag = this.tagName.toLowerCase();
    if (t == "text" || t == "password" || tag == "textarea") {
    if (this.value == "") {
    $(this).addClass("on");
    }
    } else {
    if (t == "file") {

    } else {
    if (t == "checkbox" || t == "radio") {

    } else {
    if (tag == "select" && this.selectedIndex == -1) {
    $(this).addClass("on");
    }
    }
    }
    }
    });
    }

    });
    function cl(_id) {
    $("input,select,textarea", _id).each(function () {
    var t = this.type, tag = this.tagName.toLowerCase();
    if (t == "text" || t == "hidden" || t == "password" || tag == "textarea") {
    this.value = "";
    } else {
    if (t == "file") {
    var _1e = $(this);
    _1e.after(_1e.clone().val(""));
    _1e.remove();
    } else {
    if (t == "checkbox" || t == "radio") {
    this.checked = false;
    } else {
    if (tag == "select") {
    this.selectedIndex = -1;
    }
    }
    }
    }
    });
    };
    })(jQuery);

    $(function () {
    $("#btn").click(function () {
    var res = $("#form1").validate({ "username": "用户名称不能为空" });
    });
    $("#cle").click(function () {
    var res = $("#form1").clear();
    });
    });

  • 相关阅读:
    C# 反射
    WPF之布局
    java网络编程中的BIO,NIO,AIO
    BIO的阻塞
    AttributeView的用法
    将linux文件中的tab更换为空格的三种方法
    安装nginx-ingress控制器,使用
    docker 搭建jenkins
    Manjaro 18.0.1 系统安装后值得看的两篇博客
    github创建自己的项目并进行推送
  • 原文地址:https://www.cnblogs.com/lbangel/p/3097208.html
Copyright © 2020-2023  润新知