How to clone typing to every input from the first box with jquery on checkbox checked?

后端 未结 1 1924
长发绾君心
长发绾君心 2021-01-16 05:04

I want to clone/duplicate the typing of the first input of each column in to the child boxes of the same class/id.

For example, there\'re 5 columns of data. Each col

1条回答
  •  无人及你
    2021-01-16 05:57

    This line in your code is setting all the input boxes to readonly and preventing you from typing in the first box as well.

    $('*[id^="box"]').val($this.val()).attr('readonly', true); //clone all inputs and set them readonly
    

    If you add this line beneath it, it will allow you to continue typing in the first box.

    $input1.attr('readonly', false);
    

    Updated Fiddle: http://jsfiddle.net/be9br09j/2/

    Updated Snippet

    var $input1 = $(document).find('input[id^="box"]').filter(':visible:first'); //find the first input begins with *box or other same id???
    $($input1).keypress(function() { //duplicate the first box typing
      var $this = $(this);
      window.setTimeout(function() { //delay a bit
        if ($('#cloneAll').is(':checked')) { //if checkbox empty
          $('*[id^="box"]').val($this.val()).attr('readonly', true); //clone all inputs and set them readonly
          $input1.attr('readonly', false);
        }
      }, 0);
    });
    
    1.
    
    
    
    2.
    3.
    4.
    5.
    .
    .
    .
    100.

    0 讨论(0)
提交回复
热议问题