当前位置:Gxlcms > JavaScript > JQuery文本框高亮显示插件代码_jquery

JQuery文本框高亮显示插件代码_jquery

时间:2021-07-01 10:21:17 帮助过:3人阅读

代码如下:

jquery-highlight.js

代码如下:

/*
description:TextBox HighLight
author:Allen Liu
*/
(function($) {
$.fn.highlight = function(options) {
var defaultOpt = {
lightColor: 'yellow', /* 高亮时的颜色 */
lightTime: 1000, /* 高亮时长 (单位:毫秒) */
isFocus: true /* 是否获取焦点 */
};

options = $.extend(defaultOpt, options);
return this.each(function() {
var sender = $(this);
if (sender.attr('light') == undefined) {
var _bgColor = sender.css('background-color');
sender.css({ 'background-color': options.lightColor });
if (options.isFocus) {
sender.focus();
}

sender.attr('light', true);
window.setTimeout(function() {
sender.removeAttr('light');
sender.css({ 'background-color': _bgColor });
}, options.lightTime);
}
});
}
})(jQuery);


Html代码:
代码如下:





调用方法:
代码如下: