如果html中带有 “>>”,则“>>”以及后面的所有代码被清空,请问为什么,怎样解决?例子如下:
localhost下有以下2个文件:
test.html:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>test page</title>
<script type="text/javascript" src="http://localhost/leb/auto/js/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
var html= $(".page")[0].innerHTML;
$.ajax({
cache : false,
type : "POST",
url : "file.php",
data : "html="+html,
dateType : "text"
});
});
</script>
</head>
<body>
<div class="page">
<span>more>></span>
<div>other infos</div>
</div>
</body>
</html>
file.php 文件:<?php
$html=$_POST['html'];
$file=fopen('result.html','w');
fwrite($file,$html);
fclose(file);
?>
打开test.html,jquery的ajax通过file.php生成的result.html中的代码只有<span>more后面的全没了,为什么会这样?怎么解决?
localhost下有以下2个文件:
test.html:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>test page</title>
<script type="text/javascript" src="http://localhost/leb/auto/js/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
var html= $(".page")[0].innerHTML;
$.ajax({
cache : false,
type : "POST",
url : "file.php",
data : "html="+html,
dateType : "text"
});
});
</script>
</head>
<body>
<div class="page">
<span>more>></span>
<div>other infos</div>
</div>
</body>
</html>
file.php 文件:<?php
$html=$_POST['html'];
$file=fopen('result.html','w');
fwrite($file,$html);
fclose(file);
?>
打开test.html,jquery的ajax通过file.php生成的result.html中的代码只有<span>more后面的全没了,为什么会这样?怎么解决?
$(function(){
$.ajax({
cache : false,
type : "POST",
url : "file.php",
data : {html:$(".page:eq(0)").html()},//如果只有一个.page可以去掉:eq(0)
dateType : "text"
});
});
这样试试呢?
你如果一定要直接用>的话可以在php中$html = str_replace('>','>',$html);
http://bbs.phpchina.com/thread-170942-1-1.html