我想通过jQuery点击事件来替换我的hrefs链接:因为我已经为每个关注点放置了一个insite类。JQuery:绑定点击hrefs
这是代码我已经把我的页面的底部:
$('.insite').each(function(i,a) {
$('this').click(function() {
$('#content').load(a.attr('href')+' #content');
});
});
我是不是忘了什么?
谢谢
我想通过jQuery点击事件来替换我的hrefs链接:因为我已经为每个关注点放置了一个insite类。JQuery:绑定点击hrefs
这是代码我已经把我的页面的底部:
$('.insite').each(function(i,a) {
$('this').click(function() {
$('#content').load(a.attr('href')+' #content');
});
});
我是不是忘了什么?
谢谢
您是否包含jQuery库?此外,您的代码是否包含在DOM准备好的事件中?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
$(function() {
$('.insite').click(function(e) {
$('#content').load($(this).attr('href')+' #content');
});
});
$('.insite').click(function(){
$('#content').load($(this).attr('href') + ' #content');
});
$('.insite').click(function(ev) {
$('#content').load($(this).attr('href')+' #content');
ev.preventDefault();
});
你不需要每次。 而ev.preventDefault是需要的,因此它不会在浏览器中加载href。
非常感谢! – Roch 2011-04-01 13:00:39
你不需要每个。你可以这样做:
$('.insite').click(function(e) {
e.preventDefault();
// Do stuff
});
不知道你正在尝试与$('#content').load(a.attr('href')+' #content');
做你应该使用
$(this)
,而不是
$('this')
应该是$(本)而不是$('this')。 – Rezler 2011-04-01 13:02:44