我正在尝试使用 .load 更改 onclick 事件中特定 div 的内容,由于某种原因它不起作用,我不知道为什么。我正在尝试复制此帖子中要求的完全相同的内容https://stackoverflow.com/questions/3432553/how-to-load-replace-an-entire-div-from-an-external-html-文件
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#electric').bind('click',function(){
$("#chart_div").load("new_content.html");
});
});
</script>
html
<div id="container">
<div id="chart_div">hello</div>
</div>
<ul class="nav nav-pills">
<li class="active">
<a id="electric" href="#">Electric link</a>
<li class="active">
<a href="#">Gas</a>
</ul>
new_content.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Graph</title>
</head>
<body>
<p>New Content!</p>
</body>