<!DOCTYPE html>
<html>
<head>
	<title>获取信息</title>
</head>
<body>
	<button onclick="getInfo()">获取信息</button>
	<script>
		function getInfo() {
			// 发送请求获取信息
			var xhr = new XMLHttpRequest();
			xhr.onreadystatechange = function() {
				if (this.readyState == 4 && this.status == 200) {
					// 获取信息成功,弹窗显示信息
					var info = this.responseText;
					var popup = document.createElement("div");
					popup.style.position = "fixed";
					popup.style.top = "50%";
					popup.style.left = "50%";
					popup.style.transform = "translate(-50%, -50%)";
					popup.style.background = "#fff";
					popup.style.padding = "20px";
					popup.style.border = "1px solid #000";
					popup.style.boxShadow = "0 0 10px rgba(0, 0, 0, 0.3)";
					var content = document.createElement("p");
					content.innerHTML = info;
					popup.appendChild(content);
					var confirmBtn = document.createElement("button");
					confirmBtn.innerHTML = "确认";
					confirmBtn.style.marginRight = "10px";
					confirmBtn.onclick = function() {
						document.body.removeChild(popup);
					};
					popup.appendChild(confirmBtn);
					var closeBtn = document.createElement("button");
					closeBtn.innerHTML = "关闭";
					closeBtn.onclick = function() {
						document.body.removeChild(popup);
					};
					popup.appendChild(closeBtn);
					document.body.appendChild(popup);
				}
			};
			xhr.open("GET", "http://example.com/getInfo.php", true);
			xhr.send();
		}
	</script>
</body>
</html
php编写个源码点击按钮后访问另个网页获取一个信息在原来页面弹窗出一个框体显示获取的信息内容框体带确认和关闭按钮

原文地址: https://www.cveoy.top/t/topic/hqZI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录