检测单击时另一个帧中存在的按钮

Detecting onClick of a button present in another frame

本文关键字:存在 按钮 单击 另一个 检测      更新时间:2023-09-26

在我的HTML页面中,我有两个框架 - top_framebottom_frame。在top_frame有一个按钮<input type='button' id='test' value='Test' name='test'>

现在在bottom_frame中,我想检测是否单击了top_frame中的按钮。

现在通常没有框架我可以这样做 -

$("#test").click(function(){
   alert("You Clicked Me!!");
});

如何在框架中做同样的事情?

使用 jquery 选择器的第二个参数。它设置上下文...

$("#test", window.parent.frames[0].document).click(function(){
   alert("You Clicked Me!!");
});