2013-08-17 4 views
1
<html> 
    <head> 
     <script language="Javascript"> 
      function changecolor(var c) 
      { 
      document.body.style.background=c; 
      } 
     </script> 
    </head> 
    <body> 
     <table width="300" height="100" align="center" border=2> 
      <tr> 
       <td onmouseout=changecolor("transparent") onmouseover=changecolor("red")>red</td> 
       <td onmouseout=changecolor("transparent") onmouseover=changecolor("green")>green</td> 
       <td onmouseout=changecolor("transparent") onmouseover=changecolor("blue")>blue</td> 
      </tr> 
     </table> 
    </body> 
</html> 

색상 변경이 적용되지 않습니다. 누군가 도와주세요 ...! 미리 감사드립니다. 당신은 함수 선언에 var c을 쓸 때, 브라우저가 함수의 범위에 새 변수를 선언 할 것이기 때문에자바 스크립트 변경 색상

+0

귀하의 예를 보여 jsfiddle.net을 사용하시기 바랍니다 – Ankur

+3

기능이 그들에'기능 changecolor (var에 C)'해야을 VAR이 없습니다 be changed function changecolor (c) – abc123

+2

onmouseout/onmouseover 문을 ''로 묶어야합니다. 즉, 'onmouseout = changecolor ("transparent")'는'onmouseout ='이어야합니다. changecolor ("transparent") '' –

답변

2

당신은

function changecolor(c) 

대신

function changecolor(var c) 

의 작성해야합니다. 따라서 C 변수를 사용할 때 변수에 데이터를 할당하지 않았기 때문에 undefined를 반환합니다. UR이 문제를 해결하는 것이다

function changecolor(var c) 

function changecolor(c) 

우르 자바 스크립트 함수에서

+0

왜 downvote? 그게 유일한 버그 야. –

+0

이유가 없으니 어쩌면 .. 왜 .. 가장 링크가 .. –

0

파라미터

의 타입을 선언 할 필요없이 그렇게 변경.

0
<html> 
<head> 
    <script language="Javascript"> 
     function changecolor(c) 
     { 
      document.body.style.backgroundColor=c; 
     } 
    </script> 
</head> 
<body> 
    <table width="300" height="100" align="center" border=2> 
     <tr> 
      <td onmouseout="changecolor('white')" onmouseover="changecolor('red')">red</td> 
      <td onmouseout="changecolor('white')" onmouseover="changecolor('green')">green</td> 
      <td onmouseout="changecolor('white')" onmouseover="changecolor('blue')">blue</td> 
     </tr> 
    </table> 
</body> 

0

이 시도 :

<script language="Javascript"> 
      function changecolor(c)//remove var 
      { 
      document.body.style.background=c; 
      } 
     </script> 
0
<body> 
<table width="300" height="100" align="center" border=2> 
    <tr> 
     <td id="redcolor" onmouseover="change_red()" onmouseout="change_color()">red</td> 
    <td id="greencolor" onmouseover="change_green()" onmouseout="change_color()">green</td> 
     <td id="bluecolor" onmouseover="change_blue()" onmouseout="change_color()">blue</td> 
    </tr> 
</table> 

<script> 
    function change_red() 
     { 
      document.getElementById("redcolor").style.color="red"; 
     } 

    function change_green() 
     { 
    document.getElementById("greencolor").style.color="green"; 
} 

function change_blue() 
{ 
    document.getElementById("bluecolor").style.color="blue"; 
} 

function change_color() 
{ 
document.getElementById("redcolor").style.color="#000"; 
document.getElementById("greencolor").style.color="#000"; 
document.getElementById("bluecolor").style.color="#000"; 
} 
</script> 

</body>