gpt4 book ai didi

jquery - ajax post后执行document.ready

转载 作者:行者123 更新时间:2023-12-03 21:35:18 26 4
gpt4 key购买 nike

我有一个 custom.js 文件,其中有几个元素绑定(bind)了 click 和其他方法。整个文件被封装在 document.ready() 中并且一切正常。然而,当我执行 AJAX 发布时,显然 document.ready() 永远不会再次为当前页面触发。无论如何,我是否可以让 document.ready() 再次触发,或者我是否需要让命名函数中的所有内容从我的 create.js.erb 中调用它们?

最佳答案

您总是可以将所有内容放入一个函数(名为 loadfunction 或其他名称)中,并在文档加载时调用该函数,并在加载 ajax 时再次调用该函数。虽然它是一个拼凑在一起的解决方案,但它应该工作得足够好。

然后取 $(document).onready(function () { 及其结束括号 } 之间的所有内容并将其放入以}结尾的function OnloadFunction () {中。然后放入 $document.onready(OnloadFunction);

示例:你有

$(document).ready(function () {alert("test");});

它会变成:

function OnloadFunction ()
{
alert("test");
}
$(document).ready(OnloadFunction);

然后您可以随时调用 OnloadFunction

关于jquery - ajax post后执行document.ready,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5610321/

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