根据鼠标悬停在不同 div 上更改 div 内容

Dal*_*Dal 3 html javascript mouseover

您好,这个问题是基于前一个问题的基础上的,鼠标悬停更改了其他人询问的单独 DIV 内的文本。

只是我相信最初的海报要求多次悬停,而且似乎没有人理解这个请求。我相信我正在寻找他正在寻找的东西,所以我会尽力解释它。

说我有一个 div

<div id="content">Descriptions should appear here</div>
Run Code Online (Sandbox Code Playgroud)

以及位于页面其他任何位置的链接列表及其自己的描述(只有列表可见,而不是描述)

foo = bar and stuff
apples = a red fruit
keyboard = thing you type with
boat = floats on water
Run Code Online (Sandbox Code Playgroud)

我该如何做到这一点,以便如果有人将鼠标悬停在其中一个链接上,说明就会显示在内容 div 中?


感谢所有的答复!最后,这就是我的选择:

javascript:

<script>
    function changeContent(description) {
        console.log(description);
        var MyDesc = document.getElementById(description);
        document.getElementById('content').innerHTML = MyDesc.value;
    }
</script>
Run Code Online (Sandbox Code Playgroud)

html:

<div id="content"></div>

<a onmouseover="changeContent('desc1')" href="#">Apples</a>
  <input type="hidden" id="desc1" value="apples are delicious">
<a onmouseover="changeContent('desc2')" href="#">Oranges</a>
  <input type="hidden" id="desc2" value="Oranges are healthy">
<a onmouseover="changeContent('desc3')" href="#">Candy</a>
  <input type="hidden" id="desc3" value="Candy is tasty!">
Run Code Online (Sandbox Code Playgroud)

为描述提供单独的输入使我可以选择在需要时将其拍摄下来。再次感谢所有精彩的回答!

ind*_*lee 5

该解决方案使用纯 JavaScript。

<div id="content">
    Stuff should be placed here.
</div>

<br/>
<br/>
<br/>
<ul>
    <li onmouseover="hover('Apples are delicious')">Apple</li>
    <li onmouseover="hover('oranges are healthy')">Orange</li>
    <li onmouseover="hover('Candy is the best')">Candy</li>
</ul>

<script>
    function hover(description) {
        console.log(description);
        document.getElementById('content').innerHTML = description;
    }
</script>
Run Code Online (Sandbox Code Playgroud)