空文本框检查 [英] empty text box checking

查看:66
本文介绍了空文本框检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (document.getElementById('<%=txtName.ClientID %>').values == "" && document.getElementById('<%=txtPassword.ClientID %>').values == "")

                return false; alert("Enter Username & Password");





我将这段代码反复放入警告消息中,请问我该怎么办!!!!





I am putting this code put repeatly ask alert message what can i do plz help me!!!!!

推荐答案

您应该移动alert语句 return之前.
You should move the alert statement before the return one.




您的警报应该优先.
如果您首先返回false,则剩余的代码将不会执行.因为它在返回false后终止执行.
首先放入Alert消息,然后保留return语句.它应该可以工作.



Your alert should be first.
if you first return false then remaining code will be not execute. Because its terminate the execution after return false.
Put Alert message first and then keep return statement. it should work.

if (document.getElementById('<%=txtName.ClientID %>').values == "" && document.getElementById('<%=txtPassword.ClientID %>').values == "")
alert("Enter Username &amp; Password");
return false; 



谢谢,
Viprat



Thanks,
Viprat


if (document.getElementById('<%=txtName.ClientID %>').value == "" && document.getElementById('<%=txtPassword.ClientID %>').value == "")
{
  alert("Enter Username & Password");
  return false; 
}


在大多数语言中,如果您不使用大括号来打开和关闭要检查的条件的范围,则只会影响条件之后的第一行.

正如CPallini所说,将警报放置在返回之前.
然后将{}置于条件中.

希望这会有所帮助.


In most languages if you don''t put braces to open and close the scope of the condition to be checked it only affects the first line after the condition.

As CPallini said, put the alert before the return.
And put the {} in the condition.

Hope this helps.


这篇关于空文本框检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆