我制作了一个输入框,并将这个输入框克隆到一个div中,让我们将它们命名为ipbox1和ipbox2,ipbox2是ipbox1的副本现在我想做的是当 我在其中之一输入/更改值, dom.value 或 $("#id").val() 应该返回更新的值。但现在它只能与 ipbox2 一起使用。 我该怎么办?
$("#ghj").click(function(){
$("#abc").val("Some text");
$("#abc").clone(true).appendTo("#pastehere");
})
$("#abc").on('change',function(){
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>
最佳答案
我已经更新了你的 fiddle :https://jsfiddle.net/gschambial/s6td1bof/7/
var initVal = $('#abc').val();
$("#ghj").click(function(){
$("#abc").val("Some text");
$("#abc").clone(true).appendTo("#pastehere");
})
$("#abc").on('change',function(){
alert();
initVal = $(this).val();
})
$("#get").click(function(){
alert(initVal);
})
关于javascript - 如何影响原来输入框的变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40114410/