1
有一個HTML頁面使用Ajax Load() function
加載另一個HTML文件到當前HTML文檔(到指定元素中)。當點擊Links
時,其他HTML頁面會正確加載。使用load()加載的代碼會導致DOM添加,但源代碼不會更改。您可以在頁面中看到更改的HTML,但不能看到源代碼。使用JQuery加載()函數後不要更改HTML DOM
DOM在使用JQuery Load() function
時沒有操作嗎?
代碼:
<html>
<head>
<title>JQuery Learning</title>
<script type="text/javascript" src="..//jquery-1.9.0.min.js"></script>
<script type="text/javascript">
$('document').ready(function(){
$('#newslinks a').click(function() {
var url=$(this).attr('href');
$('#headlines').load(url+' #newsItem');
return false;
});
});
</script>
</head>
<body>
<ul id='newslinks'>
<li><a href='today.html'>Today's News</a></li>
<li><a href='yesterday.html'>Yesterday's News</a></li>
<li><a href='week.html'>Last Week's News</a></li>
</ul>
<div id='headlines'>
<h3>This is headlines of News</h3>
</div>
</body>
</html>