繁体   English   中英

Uncaught SyntaxError:无效的正则表达式:缺少/,我缺少什么?

[英]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);/>

我错过了什么,或者我错过了什么? 一世

请注意区分大小写的函数名称。 此外,正如Pointy指出的那样(双关语), onClick必须在引号中。

<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);" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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