<html>
<head>
<?php
header("Content-type: text/html; charset=gbk2132");
$incPath = dirname("_FILE_");
require_once "{$incPath}/include/db_IpAddr/ipaddress.php";
require_once "{$incPath}/include/DataUse.php";
require_once "{$incPath}/messagetopic/MtoP.php";
if($_POST['btnTiJiao'])
{
$du=new DataUse();
$addr=ipCity($_SERVER['REMOTE_ADDR']);
$time=date("YmdHis");
$mp=new MtoP();
$ImgUrl=$mp->getPic($_POST["txtUserName"],$_POST["txtMessage"],$time,$addr);
$sql="insert into tblmessage (Ip,User,Message,Time,ImgUrl) " .
"values ('{$_SERVER['REMOTE_ADDR']}','$_POST[txtUserName]','$_POST[txtMessage]','{$time}','{$ImgUrl}')";
$du->query($sql);
echo "<script language=\"javascript\">alert('添加成功');history.go(-1)</script>";
}
?>
<script type="javascript">
function chk()
{
if(form_addMessage.txtUserName.value=="")
{
alert("留言人不能为空");
form_addMessage.txtUserName.focus();
return false;
}
else if(form_addMessage.txtUserName.value.length>5)
{
alert("你名字有这么长吗");
form_addMessage.txtUserName.select();
form_addMessage.txtUserName.focus();
return false;
}
if(form_addMessage.txtMessage.value=="")
{
alert("内容不能为空");
form_addMessage.txtMessage.focus();
return false;
}
else if(form_addMessage.txtMessage.value.length>60)
{
alert("精简一下祝福吧!");
form_addMessage.txtMessage.select();
form_addMessage.txtMessage.focus();
return false;
}
return false;
}
</script>
<title>送祝福啦!</title>
</head>
<form name="form_addMessage" id="form_addMessage" method="post" action="test.php" onsubmit="return chk();" >
<body>
<div style="width:980px;margin:0px auto;">
<table border="2">
<tr>
<td colspan="2" align="center">增加祝福话语</td>
</tr>
<tr>
<td style="width:200px">用户Ip</td>
<td><?php echo $_SERVER['REMOTE_ADDR']; ?></td>
</tr>
<tr>
你的form在哪里??你可以以form中添加属性onsubmit="return chk()"
<form action="" onsubmit="return chk()">///有了的,只是贴的时候贴掉了
追答<form action="" onsubmit="return chk()">///按照你的做法弄,还是不执行啊,我直接
function chk()
{
alert('123');
return false;
}
这样都不执行
会用firebug吗?你看一下这个有没有代码错误之类的。
追问这样都不行了
你没发现你代码错了吗???html代码的层次如下。
<html>有了的,只是贴的时候贴掉了
有了的,只是贴的时候贴掉了