选择要在Div中显示的列表框值,并在JavaScript中使用onmouseover

时间:2018-10-26 14:21:09

标签: javascript html

我正在尝试在Div标签中显示选择列表框值,并使用下面的代码在Div中显示值,但是当我们选择其他

时,它不能以正确的方式显示

请帮助我,我是javascript的新手,正在尝试学习,它将对我非常有帮助

$html = "";    
$result = $connection->query($query);
    if ($result) {
        if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
                $html .= "<tr>";
                $html .= "<td> data from table</td>";
                ...
                $html .= "</tr>";
            }
        }
    }
echo $html;

1 个答案:

答案 0 :(得分:0)

尝试一下:

<html>
    <head>
        <meta charset="utf-8">
            <title>Demo GetSelectOptionData</title>
        </head>
    <body>
    <form id="demoForm">
        <select name="demoSelect" id="demoSelect" onchange="showData(this.value)" size="5">
            <option onmouseover="showHoverData(this.value)" value="A">Option 1</option>
            <option onmouseover="showHoverData(this.value)" value="B">Option 2</option>
            <option onmouseover="showHoverData(this.value)" value="C">Option 3</option>
        </select>
    </form>
    <p id="secondP">&nbsp;</p>
    <p id="thirdP">&nbsp;</p>
    <script>
      function showData(val){
        secondP.innerHTML = ('Its value is: ' + val);
      }  
      function showHoverData(val){
        thirdP.innerHTML = ('Hovering over: ' + val);
      }  
    </script>
    </body>
</html>