Javascript mozilla中的焦点问题
在我的应用程序中,我使用一个带有onBlur属性的文本框来指定一个函数,我无法通过告诉Mozilla中的id来聚焦该函数,代码如下Javascript mozilla中的焦点问题,javascript,asp.net,Javascript,Asp.net,在我的应用程序中,我使用一个带有onBlur属性的文本框来指定一个函数,我无法通过告诉Mozilla中的id来聚焦该函数,代码如下 Javascript函数 函数验证密码(元素) { 元素focus(); }尝试将其更改为: <asp:TextBox ID="txtPassword" AutoCompleteType="Disabled" autocomplete="off" runat="server" MaxLength="25" Width="350p
Javascript函数
函数验证密码(元素)
{
元素focus();
}
尝试将其更改为:
<asp:TextBox ID="txtPassword" AutoCompleteType="Disabled"
autocomplete="off" runat="server"
MaxLength="25" Width="350px" TextMode="Password" onBlur="return
ValidatePassword(document.getelementById('<%=txtPassword.ClientID%>'));">
</asp:TextBox>
onblur
是客户端函数,要获取客户端文本框的值,请使用.value
而不是.text
onBlur="return ValidatePassword(this);"
function ValidatePassword(element) {
if(element.value.length < 5){
setTimeout(function(){
element.focus();
}, 100);
}
}
onBlur=“return ValidatePassword(this);”
函数ValidatePassword(元素){
if(element.value.length<5){
setTimeout(函数(){
元素focus();
}, 100);
}
}
我很困惑,当你对文本框失去焦点时,你的javascript会导致它再次聚焦吗?这是javascript函数的真实内容还是有一些验证逻辑?@Meister当我给出这个.value时,我不会得到id,所以我将它作为onBlur=“return ValidatePassword(this);”传递给function元素。focus现在也不关注Mozilla中的控件