Why can't I call a function named clear from an onclick attribute?

后端 未结 2 965
迷失自我
迷失自我 2020-11-22 01:27

i\'m trying to create a simple calculator, when a button is clicked its value is shown in the text field and the button \"C\" should clear the text field but its onclick=\"

2条回答
  •  攒了一身酷
    2020-11-22 01:45

    Your HTML has problems, but the reason your function is not working is because of its name "clear", which is already defined by document.clear().

    Change the name of that function to something like clearField() and it will work.

提交回复
热议问题