【问题标题】:Set id attribute of element to jstl variable将元素的 id 属性设置为 jstl 变量
【发布时间】:2013-06-04 08:10:48
【问题描述】:
<input type = "radio" name = "skillLevel[${status.index}].skillLevelId" id = "skillLevel[${status.index}].skillLevelId" value = "3"/>

对于输入名称属性值 skillLevel[${status.index} 工作正常,但对于 id 属性 IDE 显示错误 -

Bad value "skillLevel[   ].skillLevelId" for attribute "id" on element "input": An ID must not contain whitespace.

id 的语法:
ID 至少包含一个字符,但不得包含任何空格。

有什么办法。我只想要输入元素的唯一 id 值,因为上面的语句在循环中。在每次迭代中,我都想要唯一的 id 值。

【问题讨论】:

    标签: java jsp jstl jsp-tags


    【解决方案1】:

    试试这个id

    id = "skillLevel${status.index}"
    

    【讨论】:

      【解决方案2】:

      使用 jsp:element 和 jsp:attribute 标签解决了这个问题。这是解决方案:

      <jsp:element name="input">
          <jsp:attribute name="type">radio</jsp:attribute>
          <jsp:attribute name="id">skillLevel[${status.index}].skillLevelId</jsp:attribute>
          <jsp:attribute name="name">skillLevel[${status.index}].skillLevelId</jsp:attribute>
          <jsp:attribute name="value">3</jsp:attribute>
      </jsp:element>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-30
        • 1970-01-01
        • 2014-11-19
        • 2023-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多