<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
body{
font-size: 13px;
}
.iframe{
width: 260px;
border: 1px solid #666666;
}
.iframe .title{
padding: 5px;
background-color: #EEEEEE;
}
.iframe .content{
padding: 8px;
font-size: 12px;
}
.btn{
border: 1px solid #666666;
padding: 2px;
width: 80px;
}
</style>
<script src="../js/jquery-3.5.1.js"></script>
<script>
$(function () {
$("#button1").click(function () {
var strHtml = "";
$.ajax({
url:"Xml/7-5.xml",
dataType: "xml",
success: function (data) {
var $strUser = $(data).find("User");
strHtml += "Number:" + $strUser.attr("id") + "<br>";
strHtml += "name:" + $strUser.children("name").text() + "<br>";
strHtml += "sex:" + $strUser.children("sex").text() + "<br>";
strHtml += "email:" + $strUser.children("email").text() + "<br>";
$("#tip").html(strHtml);
}
});
});
});
</script>
</head>
<body>
<div class="iframe">
<div class="title">
<input type="button" id="button1" value="获取数据" class="btn">
</div>
<div class="content">
<div id="tip"></div>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="utf-8" ?>
<Info>
<User id="10001">
<name>taotao</name>
<sex>nan</sex>
<email>taotao@163.com</email>
</User>
</Info>