[英]jquery load links not clickable
好的,我正在將包含鏈接的單獨頁面加載到名為index.php的頁面中。 它加載正常,但是當我單擊加載的內容中的鏈接之一時,什么也沒有發生。 他們不充當鏈接。 但是如果我發出alert('hi');
load('page.html');
那么它將起作用。 有什么想法讓它在加載后不發出警報的情況下起作用? 哦,我也不能使用回調,除非有一種方法可以更新get變量,因為頁面加載有一個$ _GET變量,並且加載的頁面內的鏈接應該更新$ _GET變量。 無論如何,有沒有一種方法可以使加載頁面后的鏈接可點擊?
function load_file(dirval) {
$.ajax({
url: "data.php",
data: {dir: dirval},
success: function(data) {
$('#remote-files').html(data);
}
});
}
http://api.jquery.com/load/-包含您要執行的操作的示例。
您應該能夠在查詢字符串上傳遞數據。
示例index.php
<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function load_file(dirval) {
$.ajax({
url: "data.php",
data: {dir: dirval},
success: function(data) {
$('#data').html(data);
}
});
}
load_file('http://mysite.com');
});
</script>
</head>
<body>
<div id="data"></div>
</body></html>
data.php
<html>
<head>
</head>
<body>
<ul>
<li><a href="<?php echo $_GET['dir'] ?>/link.html">Link </a></li>
</ul>
</body>
</html>
我在您的問題中看到您在使用load函數時遇到問題。 但是,在您的代碼中,您正在使用$ .ajax。
對於動態加載頁面片段,應該使用load()方法,因為它會解析所檢索文檔的內容,並正確地呈現它。 如果您以其他答案中描述的方式使用$ .ajax ,則jQuery將輸出內容而不進行任何剝離,這是不希望的。
請考慮添加您要加載的頁面的內容以及正在使用的更新代碼。
看看我博客中有關此功能的帖子http://arecordon.blogspot.com.ar/2014/01/jquery-load-explained.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.