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

  • 相关阅读:
    首次调用u8api遇到的问题总结
    为datagridview添加自定义按钮
    我对数据库索引的初步了解
    ObjectARX 常见编译错误解决方式记录
    手动修改Visual Studio 版本互转工具
    [经验] FAS 20号指令的深入研究
    Object ARX 统一设置所有图层的RGB颜色
    ARX 选择集获得所有图形 遍历 实例 备忘
    ObjectARX2010 学习笔记002:读取已经存在的DWG文件中的内容
    利用编译时的全局声明对抗反编译
  • 原文地址:https://www.cnblogs.com/lbangel/p/3097208.html
Copyright © 2011-2022 走看看