zoukankan      html  css  js  c++  java
  • 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();
    });
    });

  • 相关阅读:
    自动化测试用例设计实例
    day07 python2与python3 编码
    day06-2 数据结构
    遇到一个关于C#调用Microsoft.Office.Interop.Word实例化的一个问题
    关于C#调用matlab生成的dll的一些经验(亲测)
    javascript 检测浏览类型和版本
    图片自适应完美兼容IE8
    Java VS .NET:Java与.NET的特点对比
    【C#点滴记录】ASP.NET 使用C# 导出Word 和Excel
    关于现在IT行业从业者一些建议
  • 原文地址:https://www.cnblogs.com/lbangel/p/3097208.html
Copyright © 2011-2022 走看看