C# 在asp.net中通过javascript获取控件Id
在我的asp.net应用程序中有一个场景,当在任何多行文本框中键入enter按钮时,我需要在现有长度中添加一个特定长度,并在另一个控件中显示它。我已经编写了一个通用javascript函数来处理“pnlEnglish”面板中的键。我可以通过检查“e.keycode==13”来找出“Enter key”key up,但是可以知道我是从哪个控件触发事件的吗??。我试图避免在文本框中添加事件,因为我必须处理太多事件。有没有更好的解决方案来实现这一点C# 在asp.net中通过javascript获取控件Id,c#,javascript,asp.net,C#,Javascript,Asp.net,在我的asp.net应用程序中有一个场景,当在任何多行文本框中键入enter按钮时,我需要在现有长度中添加一个特定长度,并在另一个控件中显示它。我已经编写了一个通用javascript函数来处理“pnlEnglish”面板中的键。我可以通过检查“e.keycode==13”来找出“Enter key”key up,但是可以知道我是从哪个控件触发事件的吗??。我试图避免在文本框中添加事件,因为我必须处理太多事件。有没有更好的解决方案来实现这一点 <asp:Panel ID="pnlEngli
<asp:Panel ID="pnlEnglish" runat="server">
<asp:TextBox ID="txtPlot" runat="server" Rows="5" TextMode="MultiLine" Width="350px" TabIndex="12"></asp:TextBox>
<asp:TextBox ID="txtLegacyPlot" runat="server" Rows="5" TextMode="MultiLine" Width="350px"TabIndex="12"></asp:TextBox>
</asp:Panel>
Javascript如下所示
$('#<%=pnlEnglish.ClientID%> input:text,#<%=pnlEnglish.ClientID%> textarea').keyup(function (e) {
if (e.keyCode == 13) {
//Need to identify the control for which I shall add the length
}
var txtLenPlot = $('#<%=txtPlot.ClientID%>').val().length;
var txtLenLegacyPlot = $('#<%=txtLegacyPlot.ClientID%>').val().length;
//The below function shows the length in length displaying control
update_chars_left(500, $('#<%=txtLengthPlot.ClientID %>'), txtLenPlot);
update_chars_left(205, $('#<%=txtLengthLegacyPlot.ClientID %>'), txtLenLegacyPlot);
});
$('#输入:text,#textarea').keyup(函数(e){
如果(e.keyCode==13){
//需要确定我将添加长度的控件
}
var txtLenPlot=$('#').val().length;
var txtlegacyPlot=$('#').val().length;
//下面的函数显示长度显示控件中的长度
更新_chars_left(500,$('#'),txtLenPlot);
更新_chars_left(205,$('#'),txtlegacyPlot);
});
在侧键向上功能中,您可以获取按下enter键的文本框的id,如下所示
$('#<%=pnlEnglish.ClientID%> input:text,#<%=pnlEnglish.ClientID%> textarea').keyup(function (e) {
if (e.keyCode == 13) {
var currTextboxId = $(this).attr('id');
//Your Code
});
$('#输入:text,#textarea').keyup(函数(e){
如果(e.keyCode==13){
var currTextboxId=$(this.attr('id');
//你的代码
});