我已经做了一个输入框,我已经将此输入框克隆到一个div,让我们将它们命名为ipbox1和ipbox2,ipbox2是ipbox1的副本现在我想要做的是,当我输入/更改任何一个值其中,dom.value或$(“#id”)。val()应返回更新后的值。但现在它只能用ipbox2运行。 我该怎么办?如何影响原始输入框中的更改?
$("#ghj").click(function(){
\t $("#abc").val("Some text");
\t $("#abc").clone(true).appendTo("#pastehere");
})
$("#abc").on('change',function(){
\t alert();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type = "text" id = "abc">This is the first box
<div id = "pastehere">
</div>This is the cloned box
<br><button type = "button" id = "ghj">
Clone
</button>
当您执行'$(#id).val()'时,您将获得具有该ID的第一个元素的值。你能澄清我到底需要什么吗? – gschambial
你可以在我的答案中查看你的问题更新的小提琴。 – gschambial