检验用户输入的信息

2024-01-05 16:53 小编

在上例中,若是用户什么信息也不写就按提交按钮,那不是白收一份邮件吗?要避免这种情况出现,就要对用户的输入信息进行检验,这就要用到<input>标记的 onclick 参数,我们在“提交”按钮的<input>标记中把onclick 设置为:onclick="test(form1)",而“test(form)”则是一个 Javascript 子程序,用来检验文本框的输入内容的,它的源代码如下:

<script language="javascript">

<!--

function test(form){

test1(form);

test2(form);

test3(form)}

function test1(form){

if (form.text1.value=="")

alert("你没有写上你的姓名,请输入姓名!")

}

function test2(form){

if (form.text2.value==""||form.text2.value.indexOf('@',0)==-1)

alert("E_mail地址不正确,请重新输入!")

}

function test3(form){

if (form.text3.value!="12345678")

alert("密码错误,请重新输入!")

}

-->

</script>

在线咨询 拨打电话

电话

13363039260

微信二维码

微信二维码