用button控制必填项的javascript怎么写
用button控制必填项,发现没有填写的提示必须填写,如果按照要求全部填写了,提交,这个javascript怎么写
------解决方案--------------------这得看你想要哪些判断条件,如果就单纯判断不为空:
<script language = "javascript ">
function OK()
{
var aa = document.getElementById( "text1 ").value;
if(aa.length== " ")
{
alert( "必须填写 ");
return false;
}
else
{
return ture;
}
}
</script>
<input type= "text " id= "text1 ">
<input type= "button " id= "button1 " value= "提交 " onclick= "OK() ">
------解决方案--------------------script language = "javascript ">
function OK()
{
var aa = document.getElementById( "text1 ").value;
if(aa.length <1)
{
alert( "必须填写 ");
return false;
}
else
{
return ture;
}
}
</script>
<input type= "text " id= "text1 ">
<input type= "button " id= "button1 " value= "提交 " onclick= "OK() ">
------解决方案--------------------if (this.txt_userPwd.Text.Trim() == " ")
{
ClientScript.RegisterStartupScript(this.GetType(), " ", " <script> alert( '密码不能为空! ') </script> ");
this.txt_userPwd.Focus();//获取焦点
return;
}
else
{
}
------解决方案--------------------前面几楼的解答应该可以了,如果是我,也是这样的试一试,你试过了没,有用么?