仅在加载div时如何运行函数? [英] How do I run a function only when a div gets loaded?
问题描述
我只想在加载div时运行一个函数.
I want to run a function only when a div gets loaded.
当我加载页面时,会加载许多文件.在列表的末尾,PHP回显了一个div.显示此内容时,jQuery应该运行一个函数.
When I load the page, a number of files are loaded. At the end of the list, PHP echoes a div. When this one is displayed, jQuery should run a function.
我可以通过点击事件来做到这一点,但是我希望它能够自动运行而无需按下按钮.
I can do this with a click-event, but I want it to work automatically, without pushing a button.
这是单击的工作方式:
$("#PP_end_show").live("click",function(){
$("#PP_head_bar").slideToggle("slow");
$("#PP_info_file_wrap").slideUp("slow");
});
这是PHP回显的div
:
<?php echo "<div id=\"PP_end_show\"></div>"; ?>
在AJAX调用之后生成输出:
The output is generated after an AJAX call:
<form id="PP_search_input" method="post" name="search_ID" ONSubmit="xmlhttpPost('PP_search_stream_client.php', 'PP_search_input', 'PP_thumb_output', '<img src=\'images/wait.gif\'>');return false; ">
<input name="search_string" type="text" class="PP_input" id="search_string" value="<?php echo $_POST['search_string']; ?>"/>
<button type="submit" class="PP_submit" id="search_submit"> search </button>
在生成的输出末尾,将打印特定的div,并应触发新的jQuery函数.
at the end of the generated output the specific div will be printed and should trigger the new jQuery function.
推荐答案
这是我要解决的问题,假设我已正确理解,其中提交PP_search_input形式的表单将返回所需的html,然后在其中javascript代码应该执行.
This is how I would tackle this issue, assuming I've understood it correctly in which the submission of the form PP_search_input, returns the html needed, in which then a the javascript code should be executed.
$('#PP_search_input').submit(function() {
$.ajax({
url: 'PP_search_stream_client.php',
type: 'post',
data: $(this).serialize(),
success: function(html) {
$(html).insertAfter('#whereToInsert') //change to however you want to insert the html
.find("#PP_head_bar").slideToggle("slow").end()
.find("#PP_info_file_wrap").slideUp("slow");
}
});
});
这篇关于仅在加载div时如何运行函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!