admin管理员组文章数量:1279175
What's the cleanest way, like 1 line of JavaScript code, to set one text box's text property to equal another?
e.g. the JavaScript way to acplish this:
txtShipCity.Text = txtCity.Text;
Thanks!
What's the cleanest way, like 1 line of JavaScript code, to set one text box's text property to equal another?
e.g. the JavaScript way to acplish this:
txtShipCity.Text = txtCity.Text;
Thanks!
Share Improve this question asked Jun 14, 2010 at 18:01 aronaron 2,88611 gold badges51 silver badges79 bronze badges 02 Answers
Reset to default 9In JavaScript:
document.getElementById('txtShipCity').value = document.getElementById('txtCity').value;
Sweeten it with jQuery:
$('#txtShipCity').val($('#txtCity').val());
Although you will probably have to use the ClientID
s of the two textboxes, so your JS might end up looking pretty nasty, like:
document.getElementById('<%= txtShipCity.ClientID %>').value = document.getElementById('<%= txtCity.ClientID %>').value;
Providing you have id
attributes on the textboxs you could easily have a one-liner in jQuery doing the following:
$("#txtShipCity").text($("#txtCity").text());
(or $("#txtShipCity").val($("#txtCity").val());
if you are dealing with an input
)
If jQuery isn't really an option then try
document.getElementById("txtShipCity").value = document.getElementById("txtCity").value
本文标签: javascriptAspnet Set Textbox 1 to Equal Textbox 2Stack Overflow
版权声明:本文标题:javascript - Asp.net Set Textbox 1 to Equal Textbox 2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741246028a2364892.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论