0

我有一个示例代码:在 index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns:fb="http://ogp.me/ns/fb#">
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>index</title>  
</head>  
<body>
<input type="text" value="" name="test" id="text_input">
<iframe src="iframe.html">
</body> 
</html>

和 iframe.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns:fb="http://ogp.me/ns/fb#">
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>iframe</title>  
<script>
function getValue(text) {
    document.getElementById('text_input').value = text;
}
</script>
</head>  
<body>
<a href="#" onclick="getValue('test');">Click</a>
</body> 
</html>

单击标签时,无法传递值“文本” from iframe to index.html,如何解决?

4

1 回答 1

1

用于parent获取iframe. 尝试这个

function getValue(text) {
    parent.document.getElementById('text_input').value = text;
}
于 2012-11-27T08:23:28.510 回答