Copy text of a field into another automatically

后端 未结 8 1203
攒了一身酷
攒了一身酷 2020-12-16 08:32

I need to copy the text entered in a field (whether it was typed in, pasted or from browser auto-filler) and paste it in another field either at the same time or as soon as

8条回答
  •  一整个雨季
    2020-12-16 08:51

    If you are using jQuery, it is very easy - you need just register the right function on the right event :)

    Here's the code:

    
    
    
    $(function(){
        var $foo = $('#foo');
        var $bar = $('#bar');
        function onChange() {
            $bar.val($foo.val());
        };
        $('#foo')
            .change(onChange)
            .keyup(onChange);
    });
    

    JSFiddle: http://jsfiddle.net/6khr8e2b/

提交回复
热议问题