我正在使用ajax通过循环插入一系列信息块。每个块都有一个标题,并在其中默认隐藏长描述。它们像手风琴一样运作,只在所有的区块中一次显示一个描述。操纵由Ajax插入的内容,而不使用回调
问题是打开第一个块的描述。我真的想用 javascript来完成这个工作。是否有可能操纵 创建ajax调用而不使用回调的元素?
<!-- example code-->
<style>
.placeholder, .long_description{
display:none;}
</style>
</head><body>
<script> /* yes, this script is in the body, dont know if it matters */
$(document).ready(function() {
$(".placeholder").each(function(){ // Use the divs to get the blocks
var blockname = $(this).html(); // the contents if the div is the ID for the ajax POST
$.post("/service_app/dyn_block",'form='+blockname, function(data){
var divname = '#div_' + blockname;
$(divname).after(data);
$(this).setupAccrdFnctly(); //not the actual code
});
});
/* THIS LINE IS THE PROBLEM LINE, is it possible to reference the code ajax inserted */
/* Display the long description in the first dyn_block */
$(".dyn_block").first().find(".long_description").addClass('active').slideDown('fast');
});
</script>
<!-- These lines are generated by PHP -->
<!-- It is POSSIBLE to display the dyn_blocks -->
<!-- here but I would really rather not -->
<div id="div_servicetype" class="placeholder">servicetype</div>
<div id="div_custtype" class="placeholder">custtype</div>
<div id="div_custinfo" class="placeholder">custinfo</div>
<div id="div_businfo" class="placeholder">businfo</div>
</body>
你必须使用回调...这是ap rime的例子,为什么它在那里:) – 2010-06-15 00:27:04