所有的鸟儿他们都知道, 他们的巢应该筑在什么地方, 鸟儿知道自己该在什么地方筑巢, 那就意味着他们了解他们自己的使命。 我们身为万物之灵的人类, 怎么会不知道,连鸟儿都知道的道理呢?
html字符过滤
html字符过滤

html字符过滤

在php中很容易就实现了,只需要在接收form内容的页面里面使用字符串替换!下面说的是直接用javascript来实现
<a>的onclick 可以 return false来阻止,但是<input type="submit">似乎不行

<html>
<head>
<title>雨夜心情</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="css/style.css" type="text/css">
<script language=javascript>
function HTMLEncodes(fString){
 if(fString!=null){
  fString =fString.replace(/>/g, "&gt;");
  fString =fString.replace(/</g, "&lt;");
  return fString;
}
}

function mysubmit()
{
if(form1.content.value==""){alert(‘请输入留言内容!’); form1.content.focus(); return false;}
      form1.username.value = HTMLEncodes(form1.username.value); 
      form1.content.value = HTMLEncodes(form1.content.value);
   alert(form1.username.value);
      form1.submit();
}

function myreset()
{
form1.reset();
form1.title.value=1;
document.titleface.src=’img/face/1.gif’;
}
</script>
</head>
<body >
<form name="form1" method="post" action="check.php" >
  <table width="50%" border="0" align="center" bgcolor="#FFFFFF">
  
    <tr align="center">
      <td colspan="4" height="144">
        <textarea name="content" rows="10" cols="56"></textarea>
      </td>
    </tr>
    <tr align="center">
      <td colspan="4" height="20"> <a href="#">
   <input type="button" value="提交" onClick="mysubmit()">
 </a>
        <a href="#"><img src="img/reset.gif" width="79" height="22" OnClick="javascript:if(!myreset()) return false;" border="0"></a></td>
    </tr>
  </table>
</form>
</body>
</html>

 

check.php

<?php
echo $_REQUEST[‘content’];
?>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注