Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery iframe中的目标按钮?_Jquery - Fatal编程技术网

Jquery iframe中的目标按钮?

Jquery iframe中的目标按钮?,jquery,Jquery,我正在做一个Android网络目录,因此我不得不使用iframes。但是,我想问,是否可以单击iframe中的一个按钮并使代码在主页面中工作 这是我的代码: function initFastButtons() { new FastButton(document.getElementById("CloseButton"), runclose); new FastButton(document.getElementById("OpenButton"), r

我正在做一个Android网络目录,因此我不得不使用iframes。但是,我想问,是否可以单击iframe中的一个按钮并使代码在主页面中工作

这是我的代码:

     function initFastButtons() {
        new FastButton(document.getElementById("CloseButton"), runclose);
        new FastButton(document.getElementById("OpenButton"), runopen);
     };
     function runclose() {
        $('.full-preview-viewer').hide();
     };
     function runopen() {
        $('.full-preview-viewer').show();
     };
这就是iframe中的按钮的外观:

<input id="OpenButton" type="image" src="products/special/product1.png" name="image" width="336" height="593"></input>


谢谢大家:)

您可以将“runclose()”和“runopen()”的定义移动到父窗口(创建iframe的文档)。然后,在iframe中,您可以修改initFastButtons()设置,将这些函数引用为“parent.runclose”和“parent.runopen”。请注意,当页面不是从同一个域请求时,这种情况通常是有限的

考虑这两个页面,“inner.html”和“outer.html”:

outer.html:

<html>
<head>
<script type="text/javascript">
window.do_action = function () {
    alert('the button was clicked!');
}
</script>
</head>
<body>
    <iframe src="inner.html"></iframe>
</body>
</html>

window.do_action=函数(){
警报('按钮已单击!');
}
inner.html:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    $('button').click(parent.do_action);
});
</script>
</head>
<body>
    <button>Click Me!</button>
</body>
</html>

$(文档).ready(函数(){
$(“按钮”)。单击(parent.do_action);
});
点击我!

您可以使用以下技术单击iframe内的按钮

var $currentIFrame = $('#IFrameId');
$currentIFrame.contents().find("#OpenButton").trigger("click");

嘿,杰森,我有点困惑。我在中创建了一个单独的jquery代码,该代码执行一个函数,该函数执行
parent.runopen()。但这不起作用(在PC上也不起作用,但这很正常)。嗨,Starx,我认为这段代码将消除我的FastButton功能,它用于在按下按钮时禁用android设备上的300毫秒等待。