聊天室技术(五) -- 指挥中心_PHP
Jun 01, 2016 pm 12:34 PM
1下面是基本的发送表单代码
<form name=inputform action='messagesend.php' target='bl' onsubmit='return(checksay());' method=POST>
<?
//下面的2个参数用于验证信息的正确性
print("<input type='hidden' name='name' value='$name'>n");
print("<input type='hidden' name='pass' value='$pass'>n");
?>
//聊天对象,注意加上 readonly 属性
<input type="text" name="talkto" size="10" maxlength="20" readonly value="所有人">
//上次聊天的发送内容
<input type='hidden' name='message' value=''>
//发送的表单文本框
<input type="text" name="msg" maxlength="120" size="34">
<input type="submit" name="Submit" value="发送">
</form>
2 检查发送内容的js
var dx ='';
function checksay( )
{
//不允许发送空的发言
if(document.inputform.msg.value=='')
{
document.inputform.msg.focus();
return false;
}
//不允许重复发言,内容相同,对象相同
if ((document.inputform.msg.value==document.inputform.message.value)&&(document.inputform.talkto.value==dx))
{
alert('发言不能重复');
document.inputform.msg.focus();
return false;
}
//两次发言内容的间隔不能小于1秒,或者发言字数大于间隔*3
t2=(new Date()).getTime()/1000;
if(((t2-t1)<1)||((t2-t1)*3<document.inputform.msg.value.length))
{
document.inputform.msg.focus();
return false;
}
//更新时间
t1=t2;
document.inputform.showsign.value=1;
//保存上次发言内容
document.inputform.message.value =document.inputform.msg.value;
//清空发言内容
document.inputform.msg.value ='';
//保存发言对象
dx=document.inputform.talkto.value;
//定位焦点
document.inputform.msg.focus();
//返回
return(true);
}
3调用信息发送程序,发布聊天者已经进入的信息
<script>
parent.bl.document.open();
parent.bl.document.write("<meta http-equiv='refresh' content='0;url=messagesend.php?name=<? print($name); ?>&&action=enter&&pass=<? print($pass); ?>'>")
parent.bl.document.close();
</script>
发言由messagesend.php处理完成,注意输出对象为bl,也就是处理发言的框架名称,这样保证发言框架的页面内容的完整
原作者:howtodo
来源:php2000.com

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the differences between Huawei GT3 Pro and GT4?

This article is enough for you to read about autonomous driving and trajectory prediction!

The Stable Diffusion 3 paper is finally released, and the architectural details are revealed. Will it help to reproduce Sora?

Have you really mastered coordinate system conversion? Multi-sensor issues that are inseparable from autonomous driving

DualBEV: significantly surpassing BEVFormer and BEVDet4D, open the book!

The first multi-view autonomous driving scene video generation world model | DrivingDiffusion: New ideas for BEV data and simulation

GSLAM | A general SLAM architecture and benchmark

'Minecraft' turns into an AI town, and NPC residents role-play like real people
