Javascript 悬停链接时更改textarea的值

Javascript 悬停链接时更改textarea的值,javascript,html,Javascript,Html,我想在将鼠标悬停在链接上时更改textarea的值。我对javascript不是很精通,也不太理解“this.”和“document.”等的复杂性 目前,我有一个文本区域“信息”,页面加载是不受欢迎的,两个链接应该改变它的值。我似乎无法使它发挥作用 我确信有一种方法可以完成我需要做的事情,但我找不到 提前感谢。创建一个函数,该函数接受所需字符串,并设置文本区域: // Select the textarea by its ID (that you need to give it) v

我想在将鼠标悬停在链接上时更改textarea的值。我对javascript不是很精通,也不太理解“this.”和“document.”等的复杂性

目前,我有一个文本区域“信息”,页面加载是不受欢迎的,两个链接应该改变它的值。我似乎无法使它发挥作用



我确信有一种方法可以完成我需要做的事情,但我找不到


提前感谢。

创建一个函数,该函数接受所需字符串,并设置文本区域:

   // Select the textarea by its ID (that you need to give it)
var textarea = document.getElementById('info');  

   // Define the function that sets the value passed
function changeTextarea( str ) {
    textarea.value = str;
}
为textarea分配一个ID,并调用onmouseover中的函数,传递要设置的字符串:

<textarea name="info" id='info'></textarea>

<a href="foo.com" onmouseover="changeTextarea('foo.com is a great site')">Foo.com</a>
<a href="bar.com" onmouseover="changeTextarea('bar.com is a terrible site')">Bar.com</a>


示例:

创建一个函数,该函数接受所需字符串,并设置文本区域:

   // Select the textarea by its ID (that you need to give it)
var textarea = document.getElementById('info');  

   // Define the function that sets the value passed
function changeTextarea( str ) {
    textarea.value = str;
}
为textarea分配一个ID,并调用onmouseover中的函数,传递要设置的字符串:

<textarea name="info" id='info'></textarea>

<a href="foo.com" onmouseover="changeTextarea('foo.com is a great site')">Foo.com</a>
<a href="bar.com" onmouseover="changeTextarea('bar.com is a terrible site')">Bar.com</a>


示例:

@Šime Vidas:在问题中并没有明确地说,但可能是。@patrick这很有意义。我认为OP是在试图用这个文本区域模拟工具提示。@Šime Vidas:是的,这是有道理的。我猜,因为OP也知道onmouseout的
onmouseout
,可以调整解决方案。@Šime Vidas:在问题中没有明确地说,但可能是这样。@patrick这样说很有道理。我认为OP是在试图用这个文本区域模拟工具提示。@Šime Vidas:是的,这是有道理的。我猜,因为OP也知道onmouseout的
onmouseout
,所以可以调整解决方案。