Html 我在iframe中有两个按钮,将文本插入父文本区域,但相互替换

Html 我在iframe中有两个按钮,将文本插入父文本区域,但相互替换,html,button,iframe,parent,Html,Button,Iframe,Parent,因此,我不希望按钮相互替换文本,而是在有更多按钮时,将第一个按下的按钮文本插入第一行,第二行插入第二行,以此类推。所以我认为有一个非常简单的答案,但我在任何地方都找不到确切的答案 以下是我遇到问题的代码: 头版: <html> <head> <title>Title</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

因此,我不希望按钮相互替换文本,而是在有更多按钮时,将第一个按下的按钮文本插入第一行,第二行插入第二行,以此类推。所以我认为有一个非常简单的答案,但我在任何地方都找不到确切的答案

以下是我遇到问题的代码:

头版:

<html>
<head>
  <title>Title</title>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <script type="text/javascript">
  function hello(string)
  {
     var name=string
     document.getElementById('myAnchor').value=name;
  }
  </script>
</head>
<body>
<form><textarea id="myAnchor"></textarea></form>
<iframe src="buttonitesti_1.html"></iframe>
</body>
</html>

编写
hello
函数是为了设置textarea的值。您需要做的是获取textarea的当前值,如果该值不是空的,请添加换行符,并附加新文本:

function hello(string)
{
    // get the current text, add a newline if not blank, and append new
    // text
    var anchorText = document.getElementById('myAnchor').value;
    if(anchorText !== "") anchorText += '\n';
    anchorText += string;
    document.getElementById('myAnchor').value=anchorText;
}

<!doctype html>  
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
</head>
<body>

<form>
    <textarea id="myAnchor"></textarea>
</form>
<iframe src="buttonitesti_1.html"></iframe>

<script>
    function hello( obj ){
        document.getElementById('myAnchor').value = obj.data;
    }
    addEventListener("message", hello, false);
</script>
</body>
</html>

标题
函数hello(obj){
document.getElementById('myAnchor')。value=obj.data;
}
addEventListener(“消息”,hello,false);
buttonitesti_1.html

<!doctype html>  
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
</head>
<body>

<input onclick="parent.postMessage('ekaknaapi', '*')" type="button">
<input onclick="parent.postMessage('tokaknaapi', '*')" type="button">

</body>
</html>

标题

当我运行代码时,按钮并没有相互替换。也许我不知道你在问什么,你能再详细一点吗?
<!doctype html>  
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
</head>
<body>

<form>
    <textarea id="myAnchor"></textarea>
</form>
<iframe src="buttonitesti_1.html"></iframe>

<script>
    function hello( obj ){
        document.getElementById('myAnchor').value = obj.data;
    }
    addEventListener("message", hello, false);
</script>
</body>
</html>