问题
Possible Duplicate:
Loading an external .htm with javascript into a div
Loading an external .htm file into a div with javascript
This is my entire code:
<html>
<head>
</head>
<body>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
$('.ajax') .click(function(e){
e.preventDefault()
$('#content').load( 'file.htm' )
})
})
</script>
<div id="content">
<p>random text</p>
</div>
<div><a href="#" class="ajax">Link</a></div>
</body>
</html>
The code works fine for loading an external file into a div in firefox, but nothing happens in chrome and IE, when I click the link. any advice ?
回答1:
While it's not the cause of the problem, it's good practice to use semicolons:
$(function(){
$('.ajax') .click(function(e){
e.preventDefault();
$('#content').load( 'file.htm' );
});
});
You'll occasionally hit some strange errors if you don't.
来源:https://stackoverflow.com/questions/11281204/loading-an-external-htm-file-to-a-div-with-javascript