【问题标题】:How to programmatically change the text of an anchor tag in a JSP如何以编程方式更改 JSP 中锚标记的文本
【发布时间】:2013-08-15 15:46:58
【问题描述】:

我希望能够根据状态字段的值更改锚标记的文本。 在页面加载时,学生状态由 ajax 请求设置。之后我想检查该状态并查看它是否处于活动状态,然后超链接应显示“停用”,否则激活。 下面我通过将状态字段硬编码为 Active 来进行测试。我想实际使用 id =student-status 中的值。 有没有办法设置类似于 $("#student-status).text() 的状态变量 示例如下:

<tr>
  <td>Status</td>
  <td id="student-status"></td>
   <c:set var ="status" scope="session" value="Active" /> <!-- want to get value from td -->
   <c:choose>
    <c:when test = "$(status == 'Active')">
     <td class="new-student-status"><a id="activate-deactivate-student" href="#">DeActivate</a></td>
</c:when>
<c:when test = "$(status== 'Inactive')">
<td class="new-student-status"><a id="activate-deactivate-student" href="#">Activate</a></td>
</c:when>
</c:choose>
</tr>

【问题讨论】:

    标签: html jsp jstl


    【解决方案1】:

    试试这一行:

    <td class="new-student-status">
       <a id="activate-deactivate-student" href="#">
          <c:out value="$(status == 'Active'?'DeActivate':'Activate')"/>
       </a>
    </td>
    

    【讨论】:

    • 感谢您的信息。但是,我不知道状态是什么 - 它显示在 字段中。因此,我想做类似 var status = $('#student-status').text() 的事情。由于这是在 .jsp 中,所以我认为我做不到。
    • 我能够通过更改锚标记的文本来解决这个问题,同时 Ajax 请求正在计算状态字段。谢谢大家的帮助。
    【解决方案2】:

    $('#student-status').html(desiredText) 会将#student-status 元素的内部文本设置为desiredText 变量的值。

    【讨论】:

    • 我希望能够阅读 $('#student-status).text() 是什么。
    猜你喜欢
    • 1970-01-01
    • 2010-09-20
    • 2014-03-06
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    • 1970-01-01
    • 2013-01-16
    • 1970-01-01
    相关资源
    最近更新 更多