我一直試圖讓開關與onmouseover和onmouseout都工作,但我不知道如何將它綁定到事件。在此先感謝您的幫助切換案例與onmouseover和onmouseout事件
<script>
function img(img){
switch(img)
{
case "showSq":
document.getElementById("square").innerHTML = '<img src="square.png">';
break;
case "hideSq":
document.getElementById("square").innerHTML = '';
break;
case "showCr":
document.getElementById("circle").innerHTML = '<img src="circle.png">';
break;
case "hideCr":
document.getElementById("circle").innerHTML = '';
break;
}}
</script>
<body>
<div id=right>
<h1> Geometry </h1>
<p>
<span onmouseover="img(showSq)" onmouseout="img(hideSq)"> SQUARE</span>,
<span onmouseover="img(showCr)" onmouseout="img(hideCr)"> CIRCLE </span>
</p>
<p> <span id="circle"> <span id="square"> </p>
</div>
你的參數應該是作爲靜態字符串 –
引號內的img('showSq')值謝謝,修正,但它仍然不能使它工作。 – Snowshoot
我只是測試它,它的工作原理! –