首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

原来是按enter可能提交按钮提交信息的,按刷新键也会自动提交

2012-12-21 
原来是按enter或者提交按钮提交信息的,按刷新键也会自动提交PHP codescript languagejavascript//判

原来是按enter或者提交按钮提交信息的,按刷新键也会自动提交

PHP code
<script language="javascript">//判断用户是否按回车键且转出的内容是否为空function inputKeyPress(){    if((event.keyCode==13)&&(document.all.chatWord.value!=null)&&(document.all.chatWord.value.length>0))    {        document.forms[0].submit();        document.all.chatWord.value='';        document.all.chatWord.focus();    }    }</script><form id="mychat" action="control.php" method="post" target="control">姓名:<input type="text" id="whoChat" name="whoChat">对<input type="text" id="chatTo" name="chatTo">说:<input type="text" id="chatWord" name="chatWord" onKeyPress="inputKeyPress();"><input type="submit" value="发送"></form>//后边这个是提交信息的,并且我怎么写最后输出到chat.txt的除了“对”“说”别的文字全是乱码<?php   $_tosay = $whoChat."对".$chatTo."说".$chatWord;   $filename = "./tmp/chat.txt";   $fp = @fopen($filename,"a+");   //读写方式打开,如果 文件不存在则尝试创建   $text=utf8_encode("a!");   $text="\xEF\xBB\xBF".$text;   @fputs($fp, $_tosay."\n");  //把$_tosay 的内容写入到$fp指向的文件   @fclose($fp);  //关闭文件释放资源?>

热点排行