Function Not working

时间:2016-04-04 19:01:23

标签: javascript jquery html5

Im trying to get the submitf() function to run. I changed click to mouseover however I keep getting the same error:

Uncaught ReferenceError: submitf is not defined

Html:

<div class="buttons-wrapper clearfix"><input id="memSubbmtit" type="button" value="Sign-up" " onmouseover="submitf() "></div>

js:

function submitf() {
    var x;
    if (confirm("Press a button!") == true) {
        x = "You pressed OK!";
    } else {
        x = "You pressed Cancel!";
    }

1 个答案:

答案 0 :(得分:1)

在HTML元素尝试引用submitf()之前定义您的函数,并确保您的HTML格式正确(我将HTML属性堆叠起来以便于阅读)。

<script>
  function submitf() {
   var x;
   if (confirm("Press a button!") == true) {
     x = "You pressed OK!";
   } else {
     x = "You pressed Cancel!";
   }
</script>

<div class="buttons-wrapper clearfix">
  <input 
     id="memSubbmtit" 
     type="button" 
     value="Sign-up" 
     onmouseover="submitf()" />
</div>