[英]one textbox value in another textbox
I want to get value of one textbox and put the same in another textbox. 我想获取一个文本框的值,然后将其放入另一个文本框。 my code is :
我的代码是:
<input type="text" value="Keyword" id="one" />
<input type="text" value="Search" id="two" />
<a href="#" id="btn">button</a>
jquery: jQuery的:
var input = $("#one");
$('#btn').click(function(){
alert('dgdhjdgj');
var oneValue = $('#one').val();
alert("one value "+ oneValue);
var twoVal = $('#two').val($(input).attr('value'));
alert('two Val' + twoVal);
});
Issue : when I change the value of textbox #one, it does not change the value of #two. 问题:当我更改文本框#one的值时,它不会更改#two的值。 thanks in advance.
提前致谢。
$(input).attr('value')
gets the value of the value attribute , which is the initial value, not the current value. $(input).attr('value')
获取value属性的值 ,它是初始值,而不是当前值。
You had it right two lines earlier. 您早两行就对了。 Use
val()
. 使用
val()
。
if all that you want to change the text of second textbox, as soon as you change the text of first textbox, just use jQuery's change
event. 如果要更改第二个文本框的文本,则只要更改第一个文本框的文本,就使用jQuery的
change
事件。
just try this then: 那就试试看吧:
$('#one').on("change",function(){
$('#two').val($(this).val());
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.