题
我需要加载与类地址的字段集后一些Ajax的内容。使用的代码在其下方将替换与AJAX内容。地址的内容。
$('.accordion .head').click(function() {
$(this).next().find('.address').after().load('http://test.dev/search/view/IdDaytrip/' + $(this).attr('id') + '.html');
$(this).next().toggle('slow');
return false;
}).next().hide();
<div style="display: none;">
<fieldset class="address">
<!-- AJAx CONTENT GOES HERE -->
<ol>
<li>Stadhouderskade 78</li>
<li> Amsterdam-Zuid</li>
<li>020-5239666</li>
</ol>
</fieldset>
<!-- BUT THE AJAx CONTENT NEEDS TO GO HERE -->
<span class="tags">Tags: museum</span>
</div>
解决方案
我通常做的是这样的:
var clicked = $(this);
$.get('http://test.dev/search/view/IdDaytrip/' + $(this).attr('id') + '.html',
function(data){
alert("Data Loaded: " + data);
$(clicked).next().find('.address').after(data);
});
其他提示
此应该工作..
$('.accordion .head').click(function() {
$next = $(this).next();
$.get('http://test.dev/search/view/IdDaytrip/' + $(this).attr('id') + '.html',
function(data){
$next.find('address').after( data );
}
).end().toggle('slow');
return false;
}).next().hide()
实际上after
需要给定的元素后的对象追加。当调用
$(this).nex().find('addresss').after()
将返回的参考:
'address' + [content appended by `after`]
因为我们没有给什么after
功能追加到的地址的,所以我们仍然load
调用$('.address')
。
使用此脚本代替:
$('.accordion .head').click(function() {
$(this).next().find('.address').after($("div/>")
.load('http://test.dev/search/view/IdDaytrip/' +
$(this).attr('id') + '.html'));
$(this).next().toggle('slow');
return false;
}).next().hide();
这创造了新的div
包裹Ajax内容,并显示在正确的道路。
不隶属于 StackOverflow