将JavaScript与Thymeleaf结合使用
我有一个html表单,它使用了Thymeleaf和SpringBoot。在我的表格中,我有两个选择,硬件或软件。我已经知道了如何根据选择的单选按钮隐藏每个部分,但是我在实际使用其中一个按钮上的数据时遇到了困难。我的意思是:将JavaScript与Thymeleaf结合使用,javascript,spring-boot,thymeleaf,Javascript,Spring Boot,Thymeleaf,我有一个html表单,它使用了Thymeleaf和SpringBoot。在我的表格中,我有两个选择,硬件或软件。我已经知道了如何根据选择的单选按钮隐藏每个部分,但是我在实际使用其中一个按钮上的数据时遇到了困难。我的意思是: Top of form: Radio input: Hardware, Software if(Hardware selected) Show "Hardware Question Section" Hide "Software
Top of form:
Radio input:
Hardware,
Software
if(Hardware selected)
Show "Hardware Question Section"
Hide "Software Question Section"
Form th:action should be hardware form object
Spring controller for form should disregard software object and NOT throw any errors
Form should submit to hardware url (mm/add-new-entry/hardware)
If error with form, redirect back and notify user.
if(Software selected)
Show "Hardware Question Section"
Hide "Software Question Section"
Form th:action should be hardware form object
Spring controller for form should disregard software object and NOT throw any errors
Form should submit to hardware url (mm/add-new-entry/hardware)
If error with form, redirect back and notify user.
使用Thymeleaf和JavaScript是否可以实现这一点?我知道我需要将逻辑放入Java中,以确保如果选择了一个,另一个不会出错。是的,使用JS&Thymeleaf是可能的。将硬件和软件部分放在2个不同的分区或具有不同ID的分区中。根据无线电输入显示/隐藏硬件/软件分区。还要将逻辑放入Java中,以确保如果选择了一个,那么另一个不会出错