昨天做了一个php留言板,为什么“添加留言”为空白时,不提示“标题的内容不能为空”,下面是我写的代码:
<html><head><title>添加留言</title><scripttype="text/javascript">functionchecksmt(){vart=...
<html>
<head>
<title>添加留言</title>
<script type="text/javascript">
function checksmt()
{
var t = document.getElementByID('title').value;
var c = document.getElementByID('content').value;
if(t.length < 1 || c.length < 1)
{
alert("标题和内容不能为空!");
return false;
}
return true;
}
</script>
</head>
<body style="margin:20px auto;background-color:#ccc">
<div style="margin:50px auto;margin-left:40px">
<form action="add.php" method="post" onsubmit="return checksmt()">
<b> 标题:</b> <input id="title" type="text" name="title" size="31"/>
<br/><br/>
<b>内容:</b> <textarea name="content" rows="10" cols="30"></textarea>
<br/><br/>
<input id="content" style="margin-left:90px" type="submit" name="smt" value="添加留言"/>
<input type="reset" name="reset" value="重置"/>
</form>
</div>
</body>
</html> 展开
<head>
<title>添加留言</title>
<script type="text/javascript">
function checksmt()
{
var t = document.getElementByID('title').value;
var c = document.getElementByID('content').value;
if(t.length < 1 || c.length < 1)
{
alert("标题和内容不能为空!");
return false;
}
return true;
}
</script>
</head>
<body style="margin:20px auto;background-color:#ccc">
<div style="margin:50px auto;margin-left:40px">
<form action="add.php" method="post" onsubmit="return checksmt()">
<b> 标题:</b> <input id="title" type="text" name="title" size="31"/>
<br/><br/>
<b>内容:</b> <textarea name="content" rows="10" cols="30"></textarea>
<br/><br/>
<input id="content" style="margin-left:90px" type="submit" name="smt" value="添加留言"/>
<input type="reset" name="reset" value="重置"/>
</form>
</div>
</body>
</html> 展开
2012-11-14 · 知道合伙人软件行家
关注
展开全部
我看出的问题是~你的content没加id,呃,还有就是其实是你的方法写错了
js
<script type="text/javascript">
function checksmt(){
var t=document.getElementById('title').value;
var c=document.getElementById('content').value;
if(t.length<1 || c.length<1){
alert('wrong');
return false;
}else{
return true;
}
}
</script>
html
<input id="title" type="text" name="title" />
<textarea id="content" name="content" ></textarea>
js
<script type="text/javascript">
function checksmt(){
var t=document.getElementById('title').value;
var c=document.getElementById('content').value;
if(t.length<1 || c.length<1){
alert('wrong');
return false;
}else{
return true;
}
}
</script>
html
<input id="title" type="text" name="title" />
<textarea id="content" name="content" ></textarea>
展开全部
<html>
<head>
<title>添加留言</title>
<script type="text/javascript">
function checksmt()
{
var t = document.getElementById('title').value;
var c = document.getElementById('content').value;
if(t.length < 1 || c.length < 1)
{
alert("标题和内容不能为空!");
return false;
}
from1.submit();
}
</script>
</head>
<body style="margin:20px auto;background-color:#ccc">
<div style="margin:50px auto;margin-left:40px">
<form action="add.html" method="post" name="from1">
<b> 标题:</b> <input id="title" type="text" name="title" size="31"/>
<br/><br/>
<b>内容:</b> <textarea id="content" name="content" rows="10" cols="30"></textarea>
<br/><br/>
<input style="margin-left:90px" type="button" value="添加留言" onClick="checksmt()"/>
<input type="reset" name="reset" value="重置"/>
</form>
</div>
</body>
</html>
<head>
<title>添加留言</title>
<script type="text/javascript">
function checksmt()
{
var t = document.getElementById('title').value;
var c = document.getElementById('content').value;
if(t.length < 1 || c.length < 1)
{
alert("标题和内容不能为空!");
return false;
}
from1.submit();
}
</script>
</head>
<body style="margin:20px auto;background-color:#ccc">
<div style="margin:50px auto;margin-left:40px">
<form action="add.html" method="post" name="from1">
<b> 标题:</b> <input id="title" type="text" name="title" size="31"/>
<br/><br/>
<b>内容:</b> <textarea id="content" name="content" rows="10" cols="30"></textarea>
<br/><br/>
<input style="margin-left:90px" type="button" value="添加留言" onClick="checksmt()"/>
<input type="reset" name="reset" value="重置"/>
</form>
</div>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询