我正在使用此函数在按键上调用textchanged函数,问题是
它调用了email.textchanged函数,但即使我在ny文本框上进行了按键操作,即使我将其命名为$($('#abcd')[0]).keypress(function ()
,也会调用相同的函数
请提出建议
<script type="text/javascript">
var hTimeOut = null;`enter code here`
$($('#email')[0]).keypress(function () {
if (hTimeOut)
clearTimeout(hTimeOut);
hTimeOut = setTimeout(function () { $($("#email")[0]).change(); }, 200);
我的aspx代码是这样的 *
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="email1" runat="server" Height="52px" Width="200px" AutoCompleteType="Email"
AutoPostBack="true" onfocus="this.value=this.value" class="email"
style="border-width:0; outline:none; border-style:none; border:none; vertical-align:middle"
BackColor="Transparent" BorderColor="Transparent" BorderStyle="None"
CssClass="stext" MaxLength="100" ></asp:TextBox>
<asp:panel ID="p1" runat="server" >
<div ID="UserAvailability" runat="server" >
<asp:Image ID="Image1" ImageUrl="images/spinner.gif" runat="server" />
</div>
</asp:panel>
<ajaxToolkit:BalloonPopupExtender ID="PopupControlExtender2"
runat="server" TargetControlID="email1"
BalloonPopupControlID="P1" Position="TopRight" BalloonStyle="Cloud"
BalloonSize="small" UseShadow="false" DisplayOnClick="true"
DisplayOnFocus="true" CacheDynamicResults="True"
/>
<ajaxToolkit:TextBoxWatermarkExtender ID="wm1" runat="server"
TargetControlID="email1"
WatermarkText="Email"
WatermarkCssClass="stext" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="email1" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
<td> <asp:UpdatePanel ID="UpdatePanssel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="username" runat="server" Height="52px" Width="200px" style="border-width:0; outline:none; border-style:none; border:none; vertical-align:middle" BackColor="Transparent" BorderColor="Transparent" BorderStyle="None" AutoPostBack="true" CssClass="stext"></asp:TextBox>
<ajaxToolkit:TextBoxWatermarkExtender ID="wm2" runat="server"
TargetControlID="username"
WatermarkText="Username"
WatermarkCssClass="stext" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="username" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
<td>
<asp:ImageButton ID="ImageButton1" ImageUrl="images/su.gif" runat="server" />
</td>
</tr>
</table>*
}
);
</script>
答案 0 :(得分:0)
看起来你想在200毫秒不活动后在keydown上针对textbox引发回发。如果它是正确的,那么你可以使用下面的脚本:
<script type="text/javascript">
var hTimeOut = null;
$(function () {
$("#<%= email.ClientID %>").live("keypress", function () {
clearTimeout(hTimeOut);
var textBox = this;
hTimeOut = setTimeout(function () {
$(textBox).change();
}, 200);
});
});
</script>