2013-07-19 4 views
3

버튼을 클릭했을 때 제 버튼이 작동하지 않는 특별한 이유가 있습니까? 여기에 코드가 있습니다.버튼 기능이 작동하지 않는 이유는 무엇입니까()?

<script> 
    function save() { 
     if (isNaN(document.form.result.value) || document.form.result.value == 0) { 
     document.getElementById('hours').innerHTML = "There was an input error, make sure that: <br> The calculator field is not empty <br> Only include numbers as an input"; 
     document.getElementById('hoursdiv').style.background = "yellow"; 
     } else { 
     savedvalue = document.form.result.value; 
     document.getElementById('hours').innerHTML = "Hours Worked This Week: " + savedvalue; 
     document.getElementById('hoursdiv').style.background = ""; 
      } 
    } 
    function clear() { 
     alert("hi"); 
    } 
    </script> 

    <div> 
    <!-- Save Button --> 
<input class = "customSubmitButton" type="button" onClick="save();" value="Save"> 

    <!-- Clear Button --> 
<input class = "customSubmitButton" type="button" onClick = "clear()" value = "Clear"> 

    <div id = "hoursdiv"> 
     <p> 
      <strong id = "hours"> </strong> 
     </p> 
    </div> 
</div> 

저장 버튼은 정상적으로 작동합니다.

+0

오류가 있습니까? cons – intuitivepixel

+0

'save'는 작동하지만'clear'는 작동하지 않습니까? – Cherniv

+0

무엇이 오류입니까? – Maverick

답변

7

함수의 이름을 변경해보십시오.

Is "clear" a reserved word in Javascript?

+1

"clear is not reserved keyword"를 참조하십시오. http://stackoverflow.com/questions/7165570/is-clear-a-reserved-word-in-javascript – showdev

+0

하지만 이름을 변경하면 작동합니다. – Maverick

+2

Javascript 콘솔에 :'document.clear()가 사용되지 않습니다. 이 방법은 아무 것도하지 않는다. ' – Barmar

관련 문제