【发布时间】:2011-06-23 10:22:07
【问题描述】:
我想使用以iframe 的 id 作为参数的处理程序来处理 iframe 上的 click 事件。
我可以通过 JavaScript 添加一个onClick 事件处理程序,如下所示,它工作正常:
iframe.document.addEventListener('click', clic, false);
但在这种情况下,我无法将参数传递给 clic()。我尝试在clic() 中打印this.id,但没有结果。
onClick HTML 属性根本不起作用,没有调用处理程序。
<html>
<head>
<script type="text/javascript">
function def() {
myFrame.document.designMode = 'on';
}
function clic(id) {
alert(id);
}
</script>
</head>
<body onLoad="def()">
<iframe id="myFrame" border="0" onClick="clic(this.id)"></iframe>
</body></html>
【问题讨论】:
-
deepi 在回答中评论:
your code (what you gave on top) is working fine. But it's working when you click exactly on the border not in side box
标签: javascript iframe onclick addeventlistener