Using “if/else” with OnClick

后端 未结 5 1273
悲&欢浪女
悲&欢浪女 2021-01-06 08:51

First of all, is it even possible to write if/else statements directly in html with onclick attribute? And if so, why is my code not working?

So this is a button. T

5条回答
  •  时光说笑
    2021-01-06 09:45

    The reason your code is not working is because you need to escape your " quotation marks, otherwise it will be interpreted as the HTML attribute symbol.

    And I agree with the others, it is a bad practice to write your JavaScript inline inside your HTML.

提交回复
热议问题