Javascript 如何在选中jquery on复选框的情况下从第一个框克隆输入到每个输入?

Javascript 如何在选中jquery on复选框的情况下从第一个框克隆输入到每个输入?,javascript,jquery,html,checkbox,Javascript,Jquery,Html,Checkbox,我想克隆/复制输入到同一类/id的子框中的每个列的第一个输入 例如,有5列数据。每列都有自己的类和特定ID。一旦我开始在每列的顶部输入上键入,并选中复选框。该列的以下/子输入开始键入相同的笔划 JS var $input1 = $(document).find('input[id^="box"]').filter(':visible:first'); //find the first input begins with *box or other same id??? $($input1).ke

我想克隆/复制输入到同一类/id的子框中的每个列的第一个输入

例如,有5列数据。每列都有自己的类和特定ID。一旦我开始在每列的顶部输入上键入,并选中复选框。该列的以下/子输入开始键入相同的笔划

JS

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
    }
  }, 0);
});
html

 1.<input type="text" value="" id="box1" /><label><input type="checkbox" id="cloneAll" />clone all</label>
<br /> 2.<input type="text" value="" id="box2" />
<br /> 3.<input type="text" value="" id="box3" />
<br /> 4.<input type="text" value="" id="box4" />
<br /> 5.<input type="text" value="" id="box5" />
<br /> .
<br /> .
<br /> .
<br /> 100.<input type="text" value="" id="box100" /><br />

1.
克隆所有

2。
3。
4。
5。



100。

代码中的这一行将所有输入框设置为只读,并阻止您在第一个框中键入内容

$('*[id^="box"]').val($this.val()).attr('readonly', true); //clone all inputs and set them readonly
如果在其下方添加此行,将允许您继续在第一个框中键入

$input1.attr('readonly', false);
更新的小提琴:

更新的代码片段

var$input1=$(document).find('input[id^=“box”]).filter(':visible:first')//查找以*框或其他相同id开头的第一个输入???
$($input1).keypress(function(){//复制第一个框的键入
var$this=$(this);
setTimeout(函数(){//延迟一点
if($('#cloneAll')。为(':checked'){//if复选框为空
$('*[id^=“box”]').val($this.val()).attr('readonly',true);//克隆所有输入并将其设置为只读
$input1.attr('readonly',false);
}
}, 0);
});

1.
克隆所有

2。
3。
4。
5。



100。

您正在将所有框设置为只读。这就是为什么您不能继续键入,因为我希望它跟随
第一个输入的键入,如果它的id为,那么如何排除它?您已经将第一个框作为变量,所以只需添加
$input1.attr('readonly',false)在将所有框设置为readonlyok的行之后,它正在工作!=>另外,第二行的
$input1
周围不需要括号。它可以是
$input1.keypress(function(){
我可以再多问一点吗?如果有超过1组的输入,我不想每次克隆时都更改代码,那该怎么办?告诉程序从何处开始键入代码的最佳方式是什么?通常不鼓励在注释中提问。请问a并在此处发布链接,我会尽力提供帮助。我有一个新的线程这里:。请帮我一把(-/\-)