2014-01-10 141 views
0

请帮我一个Iframe触发器。添加文本到iframe输入框

如何将值放入iframe的输入字段中? 我相信问题是因为布局级别而生活的。

(iframe要放在自己的网站上为HTML)

我的iFrame:

<form id="form"> 
<div id="root"> 
<iframe id="lev-iframe"> 
<html> 
<form id="form"> 
<fieldset class="fields">  
    <div class="full"> 
    <div class="part"> 
    <input class="uniqueclass" name="uniquename" type="text" value="" /> 
    </div></div> 

jQuery的

//tested #root, #form, #lev-iframe; nothing seems to work for me... 

<script type="text/javascript"> 
$(window).bind("load", function() { 

$('#root').trigger('setFieldValue', { 
name: 'uniquename', 
value: 'myvalue' 

}) }); 
</script> 
+0

此代码是奇怪。 – rybo111

+0

哈哈对不起。希望你的意思是iframe代码而不是触发器。我认为我已经接近解决问题了,但目前它对我无能为力。 – Ruud

+0

我认为你需要学习HTML的基础知识。 – rybo111

回答

0

就像你在做你无法定义IFRAME您的示例通过在IFRAME标记内添加HTML。它要么指向具有此HTML另一页:

<iframe id="lev-iframe" src="other_page.html"></iframe> 

或HTML填充programmaticaly,例如:

HTML

<iframe id="lev-iframe"></iframe> 

JS

//This code will add input box to the iframe above 
var doc = $("#lev-iframe")[0].contentWindow.document; 
var $body = $('body',doc); 
$body.html('<input class="uniqueclass" id="uniquename" type="text" value="" />'); 

一旦你有一个有效的IFRAME它的访问您需要的元素的一个简单的问题:

$("#lev-iframe")[0].contentWindow.document.getElementById('uniquename').value = 'myvalue'; 

演示:http://jsfiddle.net/wbwCu/

+0

谢谢你的建议。是不是可以将值打印到输入框(setFieldValue)而不是添加全新的输入域? – Ruud

+0

添加整个输入字段只是以编程方式创建IFRAME内容的一个示例 - 您不必这样做。如果你像第一个例子中那样通过“SRC =”定义IFRAME的HTML,那么你所需要设置的值就是最后一行代码。 –

+0

谢谢Yuriy,我设法更新了值,并最终整合了新的输入域。 – Ruud