我已經做了一個輸入框,我已經將此輸入框克隆到一個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