js很有趣的问题?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>未命名頁面</title>
<script type="text/javascript">
<!--
var xmlhttp;
function createHTTP()
{
if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
}
function GetData()
{
createHTTP();
xmlhttp.onreadystatechange = StateChange;
xmlhttp.open("GET", "http://www.csdn.net", false);
xmlhttp.send();
}
function StateChange()
{
if (xmlhttp.readystate == 4)
{
if (xmlhttp.status == 200)
{
document.getElementById('frame1').contentWindow.document.body.innerHTML = xmlhttp.responseText;
document.getElementById('frame1').contentWindow.document.onmouseup = ShowSelection;
}
}
}
function ShowSelection()
{
var selection = document.getElementById('frame1').contentWindow.document.selection;
document.getElementById('txtShow').value = selection.createRange().text;
}
//-->
</script>
</head>
<body onload="GetData()">
<input type="text" id="txtShow" style="width:400px" />
<div>
<iframe width="100%" height="100%" id="frame1">
</iframe>
</div>
</body>
</html>
大家有没有注意innerhtml读出来内容在子框架iframe中页面中出现乱码情况
不知道怎么回事