static

public.js 1.3KB

    define(["jquery"], function ($) { // 扩展jquery增加一个回车的回调,不好的方便,不能取消绑定事件 $.fn.enter = function (back) { $(this).on("keydown", function (e) { // 输入框是否有值 if (e.which == '13') { // 回车事件 back.call(this); } }); return this; }; $(function () { // 搜索框交互部分 $(".common-search").each(function (i, obj) { // 调用width()是为了让当前对元素的修改马上生效,默认应该是延迟生效,等待刷新时生效? // 在获取元素宽度,高度时或位置时,会让前面,对dom的修改马上生效 $(".common-search-input", this).focus(function () { // 输入框激活时 $(obj).addClass("common-search-active"); }); $(".common-search-input", this).blur(function () { // 输入框未激活时 $(obj).removeClass("common-search-active"); }); $(".common-search-input", this).on("keyup keydown", function (e) { // 输入框是否有值 $(obj).toggleClass("common-search-value", $(this).val() != "").width(); }); $(".common-search-input-clear", this).click(function () { // 清除按钮 $(".common-search-input", obj).val("").focus(); $(obj).removeClass("common-search-value"); // .width(); }); }); }); });