我想为 iframe 分配一个按键事件处理程序。类似于纯 JS 的东西:
document.getElementById('iframe_id').contentWindow.addEventListener('keydown',funcName, true);
我试过:
$(document.getElementById('iframe_id').contentWindow).keydown( function() {
// my func
});
但它不起作用..请帮助!
最佳答案
contentWindow
是 iframe
的 window
对象。您需要 iframe
的 document
:
$(document.getElementById('iframe_id').contentWindow.document).keydown(function() {
// my func
});
请注意,我不确定 jQuery 如何对来自其他窗口/框架的元素使用react。
关于javascript - 使用 JQuery 将事件处理程序添加到 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/549488/