【发布时间】:2011-07-21 06:45:57
【问题描述】:
我想用 jQuery 加载内容(是 html)。为什么下面的代码对我不起作用?
我使用本教程:http://net.tutsplus.com/tutorials/javascript-ajax/how-to-load-in-and-animate-content-with-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放入点击功能中:function(event){ ...然后执行event.preventDefualt()? -
op 写了
return false;与event.preventdefault一样
标签: javascript jquery