【发布时间】:2017-06-12 18:47:24
【问题描述】:
我正在尝试使用 jquery keydown 同时将一个 textbox 上的输入添加到另一个 textbox 上。出于某种原因,它不起作用,我是编码新手,因此将不胜感激和批评..!
代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Text Box1"></asp:Label><br/>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br/><br/>
<asp:Label ID="Label2" runat="server" Text="Text Box2"></asp:Label><br/>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
</form>
<script>
$('#TextBox1').keydown(function () {
$('#TextBox2').val($(this).val())
})
</script>
【问题讨论】:
-
你需要使用
Control.ClientID即$('#<%= TextBox1.ClientID %>').keydown( -
$(document).ready(function(){ $('#TextBox1').keydown(function () { $('#TextBox2').val($(this).val( )) }) });
-
我都试过了,还是不行!
-
将您的代码放入 $(document).ready。
-
或调用函数 Sys.Application.add_load(functionName);
标签: javascript c# jquery asp.net