简体   繁体   中英

Why Clear Button doens't work in my Javascript Calculator?

I'm writing a Javascript Calculator. I have issues with my clear button, it just doesn't remove the entered symbols. What do I need to change in my code to make it work? Here's my code:

 function display(val) { document.getElementById("textval").value += val; } function compute() { try { var x = document.getElementById("textval").value; var y = eval(x); document.getElementById("textval").value = y; } catch (error) { alert(error.message); } } function clrText() { console.log(clrText); document.getElementById("textval").value = ""; }
 <html> <body> <div class="title"> Calculator </div> <table border="4"> <tr> <td><input type="button" value="c" onclick="clrText()/"></td> <td colspan="3"><input type="text" id="textval" /></td> </tr> <tr> <td><input type="button" value="+" onclick="display('+')" /></td> <td><input type="button" value="1" onclick="display('1')" /></td> <td><input type="button" value="2" onclick="display('2')" /></td> <td><input type="button" value="3" onclick="display('3')" /></td> </tr> <tr> <td><input type="button" value="-" onclick="display('-')" /></td> <td><input type="button" value="4" onclick="display('4')" /></td> <td><input type="button" value="5" onclick="display('5')" /></td> <td><input type="button" value="6" onclick="display('6')" /></td> </tr> <tr> <td><input type="button" value="*" onclick="display('*')" /></td> <td><input type="button" value="7" onclick="display('7')" /></td> <td><input type="button" value="8" onclick="display('8')" /></td> <td><input type="button" value="9" onclick="display('9')" /></td> </tr> <tr> <td><input type="button" value="/" onclick="display('/')" /></td> <td><input type="button" value="." onclick="display('.')" /></td> <td><input type="button" value="0" onclick="display('0')" /></td> <td><input type="button" value="=" onclick="compute()" /></td> </tr> </table> </body> </html>

 <td><input type="button" value="c" onclick="clrText()"></td>

Remove the * / * near clrText() in your code and your it will work perfectly fine

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