Thymeleaf - How to add checked attribute to input conditionally

后端 未结 5 557
滥情空心
滥情空心 2020-12-08 07:18

As you know, input component has an attribute, checked to whether mark the checkbox as enabled by default or not.



        
5条回答
  •  误落风尘
    2020-12-08 07:53

    After digging a little, I found out the solution. There is th:checked attribute for that purpose.

    This works:

    
    

    This fails:

    
    

    If checked="" is set to input component, it's marked checked. This method is valid for custom attributesth:attr also. Consider following example:

    If flag is false, it's replaced with:

提交回复
热议问题