【问题标题】:Jquery formatting code I want to do with JSTL Core instead [closed]我想用JSTL Core代替Jquery格式化代码[关闭]
【发布时间】:2013-01-17 17:41:21
【问题描述】:

CSS:

 <style>
    body{font-family: arial; }
    .nopad{padding-bottom:5px;}
    .exBt:before {content: "[+]";float:left;padding-right:3px;}
    .exBt_nobtn {height:12px;width:12px;float:left;padding-left:50px;}
    </style>

JQuery:

 <script>
jQuery(document).ready(function(){  
jQuery(".nopad").each(function(){
if (jQuery(this).find('div').hasClass('.exBt'))
    {
    jQuery(this).find(".taskName").css('font-weight','bold'); 
    jQuery(this).find(".taskName").css('font-size','16px');
    }   
});//end each
 });//end main
 </script>

HTML:

    <div class="nopad">
    <div  class="exBt"></div>
    <div class="taskName">This is a title</div>
    </div>

    <div class="nopad">
    <div class="exBt_nobtn"></div>
    <div class="taskName">this is subcontent</div>
    </div>

   <div class="nopad">
   <div class="exBt_nobtn"></div>
       <div class="taskName">this is subcontent</div>
        </div>

此代码运行良好。我只是想让它来处理这个:

  <div class="nopad${addDivClass}">
            <c:choose>//tests if heading content has child content
              <c:when test="${item.nestHead}"> 
              //if it has content use one class(add a-+ icon)
                     <div class="extBt" id="extBt-${item.itemId}"></div>
              </c:when>
              <c:otherwise>
          //if there is no child content loaded by ajax just indent with another class
                     <div class="extBt_nobtn" id="extBt-${item.itemId}"></div>
              </c:otherwise>
             </c:choose>

我对 JSTL Core 很陌生,但我认为那样做会更干净——我只是不知道怎么做

【问题讨论】:

  • 我不清楚问题是什么。
  • 我正在寻找 jquery 所做的事情,但使用 JSTL 核心代替。只是一个 JSTL 等价物
  • 我不明白这个问题——你已经知道什么时候使用每个类了,看起来 JS 所做的只是在 .extBt 时添加更多的 CSS。使用与现在相同的逻辑并添加另一个类,或修改 extBt 类。
  • 顺便说一句,您的 HTML 无效。多个元素具有相同的id 是非法的。
  • 已更正无效部分,以免影响发布此问题的原因

标签: jquery jsp jstl


【解决方案1】:

如果我做对了,您希望您的 jstl 代码选择取决于 ajax 请求结果的内容。但这是不可能的,因为 jstl 代码在服务器端运行,而 javascript 在客户端运行。 Jist 再仔细阅读一下 jstl 和 jsp 你就会明白了:)

【讨论】:

  • 问题在于让 jsp 对其进行测试 .extBt 类是否存在,然后将更改应用于图标旁边的副本 .taskName 。我明白你关于服务器端没有获得 AJAX 的说法,但是如果另一个类中存在一个类,它可以只更改另一个 DOM 对象吗?
  • 我不确定,但是当 JSTL 代码运行时还没有任何 DOM 元素,因为 JSTL html 代码只是一个文本。
【解决方案2】:
<c:choose>
              <c:when test="${item.nestHead}"> //test for content
                     <div class="superset-head" style="font-weight:bold">${item.name}</div>//bold
              </c:when>
              <c:otherwise>
                     <div class="superset-head">${item.name}</div>//not bold


              </c:otherwise>
       </c:choose>

这就是我想要实现的目标。我正在努力学习基本语法并正确掌握。

【讨论】:

    猜你喜欢
    • 2010-12-30
    • 2022-12-19
    • 1970-01-01
    • 2013-05-23
    • 2012-01-14
    • 2010-12-13
    • 2010-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多