.net 如何在第二个文本框中显示第一个文本框的文本?
我的ASP.NET页面上有两个文本框:.net 如何在第二个文本框中显示第一个文本框的文本?,.net,asp.net,textbox,.net,Asp.net,Textbox,我的ASP.NET页面上有两个文本框: Alt 标题 当我在Alt中输入了一些文本,然后单击标题,我希望它显示与在Alt中输入的相同的文本 请帮帮我 提前谢谢。嗯,你需要更精确地说明你想怎么做,因为你有很多选择,例如 在客户端使用JavaScript、jQuery或 那么,你更喜欢哪种方式? JavaScript函数: function CaptionOnFocus() { document.getElementById('<%=Caption.ClientID%>').
提前谢谢。嗯,你需要更精确地说明你想怎么做,因为你有很多选择,例如
- 在客户端使用JavaScript、jQuery或
function CaptionOnFocus() {
document.getElementById('<%=Caption.ClientID%>').value =
document.getElementById('<%=Alt.ClientID%>').value;
}
<asp:TextBox ID="Caption" onfocus="CaptionOnFocus();" runat="server" />
- 在服务器端代码中。在标题文本框控件上设置
,使用事件处理程序,并在其中将文本复制到标题,如下所示:AutoPostBack=“True”
Caption.text=Alt.text
- 在客户端使用JavaScript、jQuery或
function CaptionOnFocus() {
document.getElementById('<%=Caption.ClientID%>').value =
document.getElementById('<%=Alt.ClientID%>').value;
}
<asp:TextBox ID="Caption" onfocus="CaptionOnFocus();" runat="server" />
- 在服务器端代码中。在标题文本框控件上设置
,使用事件处理程序,并在其中将文本复制到标题,如下所示:AutoPostBack=“True”
Caption.text=Alt.text
函数fillField(){
document.getElementById('caption').value=document.getElementById('alt').value;
}
函数fillField(){
document.getElementById('caption').value=document.getElementById('alt').value;
}
最好的方法是使用JavaScript。在ASP中进行回发确实会使您正在构建的站点速度变慢。最好的方法是使用JavaScript。在ASP中进行回发会使你正在构建的网站速度变慢。这两个文本框也可以设置在ajax更新面板中,以使打字流畅。不过,javascript将是最好的:)这两个文本框也可以在ajax更新面板中设置,以便能够顺利地键入。但是,javascript将是最好的:)
<script language="javascript">
function fillField() {
document.getElementById('caption').value = document.getElementById('alt').value;
}
</script>
<asp:TextBox id="caption" runat="server" onfocus="Javascript:fillField();" />