Jquery: Mirror one text input to another

后端 未结 5 1456
傲寒
傲寒 2020-12-09 04:45

I\'m wanting to have one text field autopopulate with whatever the other text field has being typed into it.

How do I go about this?

Thank you! Hudson

5条回答
  •  盖世英雄少女心
    2020-12-09 05:03

    Dustin Diaz has written a wonderful mirror for Twitter Widget using jQuery

    $.fn.mirror = function (selector) {
        return this.each(function () {
            var $this = $(this);
            var $selector = $(selector);
            $this.bind('keyup', function () {
                $selector.val(($this.val()));
            });
        });
    };
    

    Use it like

    $('#source_text_id').mirror('#destination_text_id'); 
    

提交回复
热议问题