Coder Social home page Coder Social logo

highlight's Introduction

JQuery 文本框高亮显示插件

以前使用Mootools Js框架,文本框有个$('id').highlight()高亮方法,使其高亮显示; JQuery 中没有这个方法,自己今天写了一个Plugin,把代码贴出来分享一下;

代码如下:

/* description:Elements 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代码
<input type="text" id="txtBox" />
<input type="password" id="txtPwd" />
<input type="button" id="btnHighLight" value="highlight" />

//调用
<script src="Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-highlight.js" type="text/javascript"></script>
<script type="text/javascript">
        $(document).ready(function() {
            $('#btnHighLight').click(function() {
                $('#txtBox').highlight({lightColor:'red', lightTime: 1000 });
                $('#txtPwd').highlight({ lightTime: 1000 });
            });
        });
</script>

highlight's People

Contributors

likui0623 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.