html字符过滤
2006-01-07  作者:amao  同分类文章
description:

在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'];
?>



相关
fckeditor用javascript创建(结合ajax)
TEXTAREA自适应文字行数的多少
proxy.flyy.info使用的最简单的ajax教程
用javascript让页面的外部连接都在新窗口打开
实现flash背景透明
JavaScript中this关键字使用方法详解
把flyy.info的首页从做了一下
各种颜色值
页面上所有的链接都在新窗口打开
CSS布局基础--水平和垂直居中