在将来添加处理程序以形成div内部 [英] Adding handler to form inside div, in the future

查看:104
本文介绍了在将来添加处理程序以形成div内部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码将表单的结果指向特定的div。

I am using the following code to direct the results from a form to a specific div.

$(window).load(function () {
  $("#form1").submit(function() {
      $.post($(this).attr("action"), $(this).serialize(), function(html) {
        $("#resultsDiv").html(html);
      });
     return false; // prevent normal submit
  });
});

如何将此(或任何)处理程序应用于可能在更新的div中创建的未来表单(在未来的某个时候,新的内容将会插入到div中)?

How can I apply this (or any) handler to future forms that may be created within an updated div ( with new yet to created content inserted into the div at some point in the future)?

我已经看过.on但是我没有看到更新或重新加载div。

I have looked at the .on but I do not see an event for the updating or reloading of a div.

我已经尝试添加类似的功能到上面,但用(#thefutureDivID)替换(窗口),但没有运气。

I have tried adding a similar function to the above, but replacing (window) with ("#thefutureDivID"), but no luck.

推荐答案

添加处理程序的最佳位置就在您知道元素存在之后。所以,在这一行之后:

The best place to add the handler is right after you know the element exists. So, right after this line:

$("#resultsDiv").html(html);

您可以添加引用 $(#thefutureDivID)的代码

这篇关于在将来添加处理程序以形成div内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆