判断文本框是否为空

<html><head></head><bodystyle="background-color:teal;"><formname="form1"action="javas... <html>
<head>
</head>
<body style="background-color: teal;">

<form name = "form1" action="javascript: method="post" >
<h3>请输入你信息</h3>
姓名
<input type="text" id="name"/></br>
班级
<input type="text" id="class"/></br>
专业
<input type="text" id="Professional"/></br>
<dr>
<input type="button" onclick="qq()" value="提交"/>
</dr>
<dr>
<input type="reset" value="重置" /></dr>
</tr>
</body>
</html>

姓名和班级不能为空这要什么写?
在线等·求大神
展开
 我来答
智宝看电视
推荐于2017-09-29 · TA获得超过2197个赞
知道大有可为答主
回答量:1734
采纳率:66%
帮助的人:855万
展开全部
<script >
function qq() {

if( document.getElementById('name').value==''){
alert("姓名不能为空");
}

if( document.getElementById('class').value==''){
alert("班级不能为空");
}

}
</script>
没有经过测试,你试试吧 就是这个思路
追问
给个全的吧
追答
把这个加到你的那段代码最下面就可以
lifei602
2012-07-10 · TA获得超过186个赞
知道小有建树答主
回答量:178
采纳率:0%
帮助的人:125万
展开全部
你的代码真是错误百出,我给你全部修改了一下:
<html>
<head>
<script type="text/javascript">
function qq(){
if(document.getElementById("name").value==""){
alert("姓名不能为空");
return false;
}
if(document.getElementById("class").value==""){
alert("班级不能为空");
return false;
}
return true;
}
</script>
</head>
<body style="background-color: teal;">
<form name = "form1" action="javascript" method="post">
<h3>请输入你信息</h3>
姓名 <input type="text" id="name"/><br/>
班级 <input type="text" id="class"/></br/>
专业 <input type="text" id="Professional"/><br/>
<input type="submit" onclick="return qq()" value="提交"/>
<input type="reset" value="重置" />
</body>
</html>
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2012-07-10
展开全部
<html>
<head>
<script language="javascript">
function qq()
{
if(document.getElementById("name").value==""||document.getElementById("class").value=="")
{
alert("姓名和班级不能为空");
}
}
</script>
</head>
<body style="background-color: teal;">

<form name = "form1" action="javascript: method="post" >
<h3>请输入你信息</h3>
姓名
<input type="text" id="name"/></br>
班级
<input type="text" id="class"/></br>
专业
<input type="text" id="Professional"/></br>
<dr>
<input type="button" onclick="qq()" value="提交"/>
</dr>
<dr>
<input type="reset" value="重置" /></dr>
</tr>
</body>
</html>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式