```html
body {
fontfamily: Arial, sansserif;
margin: 20px;
}
h1 {
textalign: center;
}
form {
maxwidth: 600px;
margin: 0 auto;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin: 10px 0;
}
input[type="submit"] {
width: 100%;
padding: 10px;
backgroundcolor: 007bff;
color: fff;
border: none;
cursor: pointer;
}
input[type="submit"]:hover {
backgroundcolor: 0056b3;
}
.result {
maxwidth: 600px;
margin: 20px auto;
border: 1px solid ccc;
padding: 20px;
}
document.getElementById('nbaForm').addEventListener('submit', function(event) {
event.preventDefault();
var searchQuery = document.getElementById('searchInput').value.trim();
if (searchQuery !== '') {
fetchData(searchQuery);
} else {
document.getElementById('resultContainer').innerHTML = '
请输入有效的球员或球队名称。
';}
});
function fetchData(searchQuery) {
// 在此添加与服务器交互的代码,获取NBA数据
// 这里假设从服务器返回一个示例数据作为演示
var sampleData = {
playerName: '勒布朗·詹姆斯',
team: '洛杉矶湖人',
pointsPerGame: 25.0,
assistsPerGame: 8.0,
reboundsPerGame: 7.5,
teamWins: 50,
teamLosses: 20
};
// 构建结果字符串
var resultHTML = `
所属球队: ${sampleData.team}
场均得分: ${sampleData.pointsPerGame}
场均助攻: ${sampleData.assistsPerGame}
场均篮板: ${sampleData.reboundsPerGame}
所属球队战绩: ${sampleData.teamWins}胜 ${sampleData.teamLosses}负
`;
document.getElementById('resultContainer').innerHTML = resultHTML;
}