마스터 페이지를 사용하는 로그인 페이지가 있는데 자바 스크립트를 통해 유효성 검사를 적용했지만 작동하지 않습니다.Javascript가 마스터 페이지에서 작동하지 않습니다.
<script type="text/javascript">
function checkField(form)
{
var id = document.getElementById('<% =txtLoginId.ClientID %>').value;
var pwd = document.getElementById('<% =txtPassword.ClientID %>').value;
alert("testing" + id);
if ((id == '' && pwd != '')|| (id == null && pwd != null)) {
lblUserId.visible = true;
form.txtLoginId.focus();
return false;
}
if ((pwd == '' && id != '') || (pwd == null && id != null)) {
lblPwd.visible = true;;
form.txtPassword.focus();
return false;
}
if ((id == '' && pwd == '') || (id == null && pwd == null)) {
lblBoth.visible = true;
form.txtLoginId.focus();
return false;
}
}
</script>
나는 이름에 어떤 값을 줄 경우 그 경고에 저를 표시하지만 그때 어떤 가치를 제공하지 않는 경우 조건이 작동해야하지만이 작동하지 않는 경우, 경고가 그냥 "테스트"를 보여줍니다. 여기 내 HTML 코드입니다.
<form id="form" method="post" action="Login.aspx">
<div style="left:37%;position:absolute;top:55%;background-color:red">
<table style="left:0%; position:absolute;top:0%; width: 265px">
<asp:Label ID="lblUserId" runat="server" ForeColor="Red" Visible="false" Text="* Username is Required!"></asp:Label>
<asp:Label ID="lblPwd" runat="server" ForeColor="Red" Visible="false" Text="* Passowrd is Required!"></asp:Label>
<asp:Label ID="lblBoth" runat="server" ForeColor="Red" Visible="false" Text="* Username and Password are Required!"></asp:Label>
</table>
</div>
<div style="left:37%;position:absolute;top:60%;background-color:red">
<table style="left:0%; position:absolute;top:0%; width: 265px;border:solid;background-color:darkorange">
<tr align="center">
<td align="center">
<asp:Label ID="lblHead" runat="server" Font-Bold="true" Text="Mobile Customer Order Tracking"></asp:Label>
</td>
</tr>
</table>
</div>
<div style="left:37%;position:absolute;top:65%">
<table style="border:solid;">
<tr>
<td>
<asp:Label ID="lblLoginId" runat="server" Text="Login ID"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLoginId" ClientIDMode="Static" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblPassword" runat="server" Text="Password"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtPassword" TextMode="Password" ClientIDMode="Static" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID ="lblRemember" runat="server" Text="Remember My ID"></asp:Label>
<asp:CheckBox ID ="chkRemember" runat="server" />
</td>
<td align="right">
<asp:Button ID="btnLogin" runat="server" text="Login" OnClientClick="return checkField(this);"/>
</td>
</tr>
</table>
</div>
</form>
조건의'|| '부분을 제거하십시오. 느슨한 평등을 사용할 때'null '도'==' ''으로 검사됩니다. – Teemu
그것도 그런 식으로 작동하지 않습니다 .. –
버튼을 함수가 아닌 폼으로 전달하기 때문에'form.txtLoginId'는'checkField()'에서'undefined'입니다. 그러면 코드가 깨지고'false'가 반환되지 않습니다. 오류 메시지를보기 위해 콘솔을 열지 않았습니까? – Teemu