我有两个输入字段:
<input type="text" id="one" name="one" />
<input type="text" id="two" name="two" />
我想这样做,以便将输入到id 1中的任何内容自动放入id 2中。
有关如何执行此操作的任何想法?可能需要JavaScript吗?
只需input
在源中注册一个偶数处理程序,textfield
然后将值复制到目标即可textfield
。
window.onload = function() {
var src = document.getElementById("one"),
dst = document.getElementById("two");
src.addEventListener('input', function() {
dst.value = src.value;
});
};
// jQuery implementation
$(function () {
var $src = $('#three'),
$dst = $('#four');
$src.on('input', function () {
$dst.val($src.val());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<strong> With vanilla JavaScript</strong>
<br />
<input type="text" id="one" name="one" />
<input type="text" id="two" name="two" />
<br />
<br />
<strong>With jQuery</strong>
<br />
<input type="text" id="three" name="three" />
<input type="text" id="four" name="four" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句