我正在使用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