<!doctype html>
<html><head>
<meta http-equiv="Content-Type" content="application/json; charset=utf-8">
<title>用户输入什么,页面就显示什么。(如:换行, '"<br>等)</title>
</head>
<body>
<?php
require_once("conn.php");
$sql="select * from x";
$rs=query($sql);
$row=mysql_fetch_array($rs);
$name=$row["name"];
$s=json_encode(array("name"=>$name));
mysql_close($con);
?>
<div></div>
<textarea style="width:100%;height:150px;"></textarea>
<input>
<p></p>
<script src="js/jquery-2.1.1.min.js"></script>
<script>
var R={
HtmlEncode:function(s){
return s.replace(/&/g, '&').replace(/\"/g, '"').replace(/</g, '<').replace(/>/g, '>').replace(new RegExp(String.fromCharCode(10),'g'),"<br>");
},
HtmlDecode:function(s){
return s.replace(/&/g, '&').replace(/"/g, '/"').replace(/</g, '<').replace(/>/g, '>');
}
};
var d=<?php echo $s;?>,name=d.name;
$("div").html(R.HtmlEncode(name));
$("textarea").val(name);
$.ajax({
url:"Y.php",
dataType:"json",
success:function(d){
var name=d.name;
$("p").html(R.HtmlEncode(name));
}
})
$("input").val(R.HtmlDecode($("div").html()));
</script>
</body>
</html>