html - 使用 jsp 有条件地显示 html 元素

标签 html jsp conditional show

我想根据从数据库中读取的 bool 值显示第二个密码输入字段。从数据库读取的代码已经写好了,而且可以运行。我遇到的问题是列表元素的条件显示。 我对 jsp 知之甚少——用谷歌搜索答案,并得出以下结论,女巫不起作用。 代码:

			<ul>
				<li><label for="username">Username</label>
					<input type="username" name="username" placeholder="username" required>
				</li>
				<li><label for="password">Password</label>
					<input type="password" name="password" placeholder="password" required>
				</li>
				<!-- conditional display of a second password field -->
				<% 
					if (@showDoublePasswords == true) { 
				%>
					<li><label for="password">Password 2</label>
						<input type="password" name="password" placeholder="password" required>
					</li>
					
				<% } %>
            </ul>

最佳答案

试试这个

<ul>
                <li><label for="username">Username</label>
                    <input type="username" name="username" placeholder="username" required>
                </li>
                <li><label for="password">Password</label>
                    <input type="password" name="password" placeholder="password" required>
                </li>
                <!-- conditional display of a second password field -->
                <% 
                    //Remove '@' 
                    if (showDoublePasswords == true) 
                    { 
                %>
                      <li><label for="password">Password 2</label>
                          <input type="password" name="password" placeholder="password" required>
                    </li>

                <% } 
                %>
            </ul>

*

关于html - 使用 jsp 有条件地显示 html 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32585039/

相关文章:

ruby - 如何使 Ruby 变量在条件表达式中的计算结果为 false

php - 使用 PHP 的动态 CSS

javascript - 根据选择更改颜色

java - 是否可以在 jsp 中根据条件设置页面内容类型或为单个 jsp 设置不同的内容类型

php - 在 Woocommerce 产品类别文件中加载特定元素

java - Java 中的 1 行 IF 语句

javascript - Google Charts X Javascript X HTML - 下拉过滤器无法正常工作

javascript - ng-hide 元素下的 GIF

java - Freemarker 模板中的 JSP 标签

javascript - 从属下拉列表不起作用