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();
    });
    });

  • 相关阅读:
    Win10怎么默认用Windows照片查看程序打开图片
    Class类文件结构——访问标志
    栈的压入弹出序列
    Java中length,length()以及size()的区别
    包含min函数的栈
    extends和implements的区别
    顺时针打印矩阵
    二叉树的镜像
    Class类文件结构解读——常量池
    进制、字(word)、字节(byte)、位(bit)的关系
  • 原文地址:https://www.cnblogs.com/lbangel/p/3097208.html
Copyright © 2011-2022 走看看