简体   繁体   中英

Uncaught SyntaxError: Invalid regular expression: missing /, what am I missing?

JAVASCRIPT

<script type="text/javascript">
function addnumber(element){
  document.getElementById(`mvar`).value = document.getElementById(`mvar`).value+element.value;
}
</script>

HTML

 <form action="" method="" name="vform">
    <input id=mvar type="text" value="" name="mvar"/><br/>
    <input type="button" class="fbutton" name="1" value="1" id="1" onClick=addNumber(this);/>
    <input type="button" class="fbutton" name="2" value="2" id="2" onClick=addNumber(this);/>
    <input type="button" class="fbutton" name="3" value="3" id="3" onClick=addNumber(this);/>

What am I missing, or where am I missing something? I

Note the case-sensitive function name. Also, as Pointy points out (pun intended), the onClick had to be in quotes.

<script type="text/javascript">
    function addNumber(element){
        var myVar = document.getElementById('mvar');
        myVar.value = myVar.value + element.value;
    }
</script>

<form action="" method="" name="vform">
<input id="mvar" type="text" value="" name="mvar"/><br/>
<input type="button" class="fbutton" name="1" value="1" id="1" onClick="addNumber(this);" />
<input type="button" class="fbutton" name="2" value="2" id="2" onClick="addNumber(this);" />
<input type="button" class="fbutton" name="3" value="3" id="3" onClick="addNumber(this);" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM