<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JS</title> <style> #box{ 600px; height:200px; padding:20px; border:1px solid #999; } </style> </head> <body> <h1>ajax跨域请求操作实例</h1> <hr> <button onclick="loadHtml()">加载</button> <div id="box"></div> <script> //http://127.0.0.1/s32/JS10_Jquery01/lessson/2.php function loadHtml(){ //创建script var script = document.createElement("script"); script.src = "http://127.0.0.1/s32/JS10_Jquery01/lessson/2.php"; //把script元素追加到body document.body.appendChild(script); //删除 document.body.removeChild(script); } //定义函数 function addHtml(data){ document.getElementById('box').innerHTML = data; } </script> </body> </html>