gpt4 book ai didi

php - 如何仅在加载 div 时运行函数?

转载 作者:可可西里 更新时间:2023-11-01 13:02:47 25 4
gpt4 key购买 nike

我只想在加载 div 时运行函数。

当我加载页面时,会加载许多文件。在列表的末尾,PHP 回显一个 div。当显示这个时,jQuery 应该运行一个函数。

我可以通过单击事件来完成此操作,但我希望它自动运行,而无需按下按钮。

这是点击一下的方式:

$("#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 调用后生成输出:

<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 函数。

最佳答案

这就是我将如何解决这个问题,假设我已经正确理解提交表单 PP_search_input 返回所需的 html,然后应该在其中执行 javascript 代码。

$('#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");
}
});
});

关于php - 如何仅在加载 div 时运行函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6242619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com