【发布时间】:2014-12-06 16:33:17
【问题描述】:
伙计们,我正在尝试使用 jQuery 单击 iframe 内的按钮。
这是我创建的函数:
<script type="text/javascript">
function ClickTheButton()
{
$('#InnerIframe').contents().find('#SuperWebF1').trigger( "click" );
}
</script>
这是按钮被 iframe 调用时的 HTML 代码:
<button type="button" id="SuperWebF1" title="Continue" class="button">Continue</button>
这是 iframe 的 HTML 代码:
<div id="OutDiv" class="outerdiv">
<iframe src="http://beta.sportsdirect.bg/checkout/onepage/" id="InnerIframe" class="FrameCSS" scrolling="no"></iframe>
</div>
当我在 Chrome 的控制台中运行 ClickTheButton() 时,我收到了这个错误:
TypeError: Cannot read property 'contents' of null
当我执行这个功能时,按钮没有被点击,但它必须是......
各位,我的错在哪里? 如何点击 iframe 内的按钮?
提前致谢!
【问题讨论】:
标签: javascript jquery html iframe