更新时间:2023-02-15 15:14:28
只要您的iframe src来自同一域,它就可以工作:
So long as your iframe src is from the same domain this will work:
$(document).ready(function () {
var f = $('#myframe')[0];
var win = f.contentWindow;
//Created test environment in IFrame with ID "myframe"
$(win.document.body).append('<form><input type="submit" value="click me"/></form>');
$(win.document).on('submit', function () {
setTimeout(function () { $(f).remove(); }, 1000)
});
});
只需删除该元素,但请记住,您无法从非同一域的iframe获取contentDocument.
Simply remove the element but remember you can't get the contentDocument from an iframe that is not of the same domain.
工作解决方案: https://jsfiddle.net/f3eayurw/