【问题标题】:Style attribute is not working in Play framework样式属性在 Play 框架中不起作用
【发布时间】:2014-11-13 08:37:17
【问题描述】:

在 play-framework 2.3.x 中创建一个表单并希望根据模型属性显示/隐藏它。一般来说,如果我硬编码style = "display: none"style = "display: block" 之类的样式属性,它可以工作,但是当我想根据从控制器传递的属性更改样式时,样式根本不起作用。

下面是 index.scala.html 中的代码。 getResultStyle 方法用于生成显示样式,并用作表单标签中样式属性的值。

@getResultStyle() = @{
  if(sf.year_1(1) == 0) {"display: none"} else {"display: block"}
} @main(message) {
     <form id="Forecast Result" name="Forecast Result"
        style=@getResultStyle()
        action="" method="post">
      .
      .
     </form>

有没有办法让它工作?

【问题讨论】:

    标签: html css scala playframework


    【解决方案1】:

    将行更改为(在定义周围添加“”):

     style="@getResultStyle()"
    

    您的代码看起来像(在 html 中-在浏览器中检查)

    <form id="Forecast Result" name="Forecast Result"
            style=display:none
            action="" method="post">
    

    【讨论】:

    • 谢谢,我没有登录浏览器。
    • 在我的浏览器中看起来好像 style="display:" none
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 2023-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多