0
我想用jQuery加載內容(是html)。爲什麼下面的代碼不適合我?
我使用本教程:http://net.tutsplus.com/tutorials/javascript-ajax/how-to-load-in-and-animate-content-with-jquery/
用jQuery加載內容不刷新
HTML:
點擊每個此鏈路負載頁它(HREF)的。
<div id="icon">
<a href="http://localhost/test/test2.php" id="delete_icon"></a>
<a href="<?=base_url();?>admin/tour/insert_foreign" id="add_icon" ></a>
<a href="http://localhost/test/1st.htm" id="edit_icon" ></a>
<a href="http://localhost/test/index1.php" id="print_icon"></a>
</div>
JS:
var hash = window.location.hash.substr(1);
var href = $('#nav li a').each(function() {
var href = $(this).attr('href');
if (hash == href.substr(0, href.length - 5)) {
var toLoad = hash + '.html #content';
$('#content').load(toLoad)
}
});
$('#icon a').click(function() {
var toLoad = $(this).attr('href') + ' #content';
$('#content').hide('fast', loadContent);
$('#load').remove();
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0, $(this).attr('href').length - 5);
function loadContent() {
$('#content').load(toLoad, '', showNewContent())
}
function showNewContent() {
$('#content').show('normal', hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
你試圖把'event'在點擊功能:'函數(事件){...'然後做了'event.preventDefualt()'? –
op寫了'return false; ''和'event.preventdefault'一樣 – Vivek