这样试试:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script>
<title>我的HTML JS笔记</title>
</head>
<body>
<script>
var jstxt = document.getElementById('txt');
function readtxt()
{
var xhr = new XMLHttpRequest();
alert(xhr.status);
xhr.open('get','test.html',true);
xhr.send();
alert(xhr.status);
xhr.onreadystatechange = function ()
{
alert(xhr.status);
if (xhr.readyState == 4 && xhr.status == 200)
{
alert("请求服务器数据成功且返回数据成功!");
jstxt.innerHTML = xhr.responseText;
};
};
};
</script>
<h1 align="center">我的 html js 相关笔记</h1>
<a href="test.html" target="_blank">自动循环显示图片(查看效果)</a>
<button onclick="readtxt()" >查看源码</button>
<p>
<p><textarea id="txt" name="result" cols="60" rows="30" value="">
</body>
</html>
|