Using “if/else” with OnClick

后端 未结 5 1307
悲&欢浪女
悲&欢浪女 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:38

    sweetamylase's reply is best but you may also consider:

    If your onclick= assignment is enclosed in double quotes (onclick="...") then try using only single quote characters inside of those double quotes (or vice versa).

    This can make things easier when you need to make assignments to the onclick event when inserting elements dynamically and having separate script functions isn't really a good option.

    Example:

    
    

提交回复
热议问题