【问题标题】:Detect dynamic form input change检测动态表单输入变化
【发布时间】:2015-07-31 17:51:39
【问题描述】:

当我的表单输入发生更改时,我尝试执行一项操作,但它不起作用。我的表单是动态添加的:

<iframe onload="javascript:parent.scrollTo(0,0);" 
  height="447" allowTransparency="true" frameborder="0" scrolling="no" 
  style="width:100%;border:none" src="https://emu.edu/machform/embed.php?id=38142"
  title="Form"><a href="https://emu.edu/machform/view.php?id=38142" title="Form">Form</a>
</iframe>

这是我的 jQuery:

function doThis() {
    alert("Form changed!");
}

$("iframe").on('change', 'input', doThis);

【问题讨论】:

  • 主页和iframe是否在同一个域中?可以在这里看看:stackoverflow.com/questions/364952/…
  • 这是一个安全错误:Both frames are sandboxed and lack the "allow-same-origin" flag。查看控制台。
  • 你可以试试$("iframe").contents().find("input").on("change", doThis); 吗?
  • Vidul,我想用 jsfiddle 重新创建问题是行不通的。即使起源匹配,它也不起作用。
  • czheo,这似乎并没有改变任何东西(双关语)。

标签: javascript jquery html events onchange


【解决方案1】:

您必须等待 iframe 加载:

$('iframe').load(function() {
  $("iframe").contents().find("input").on("change", doThis);
});

【讨论】:

    猜你喜欢
    • 2020-05-30
    • 1970-01-01
    • 2021-03-29
    • 2022-12-22
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    • 2018-06-13
    • 1970-01-01
    相关资源
    最近更新 更多