【问题标题】:JQuery not applying on JSF Dynamic UI ComponentJQuery 不适用于 JSF 动态 UI 组件
【发布时间】:2012-04-25 16:37:37
【问题描述】:

在 JSF 数据表上应用 JQuery 时遇到问题。

我的代码是这样的:

<script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $('<b>#example</b>').dataTable( {
                    "aoColumns": [
                        { "asSorting": [ "asc" ] },
                        { "asSorting": [ "asc" ] },
                        { "asSorting": [ "desc", "asc", "asc" ] },
                        { "asSorting": [ "desc" ] },
                        { "asSorting": [ "asc" ] },
                        { "asSorting": [ "asc" ] }
                    ]
                } );
            } );
        </script>

XHTML

<h:dataTable id="example" name="example" value="#{notificationBean.notificationList}" var="item"
                cellpadding="0" cellspacing="0" border="0"
                styleClass="display"
                rowClasses="gradeC"
                style="background-image: url('../images/ClientCare_Menu_Gradient.jpg'); background-repeat: repeat-x;">

渲染时:

<table id="searchform:example" class="display" cellspacing="0" cellpadding="0" border="0" style="background-image: url('../images/ClientCare_Menu_Gradient.jpg'); background-repeat: repeat-x;">

现在我的问题是必须申请数据表的 CSS 没有得到应用。

我尝试了不同的符号仍然没有用 在 Jquery 我试过:

${'#searchform:example'}, ${'#searchform.example'} 在这些情况下,包含表本身的悬停操作将无法显示数据表。

${'searchform#example'}, ${'#example'} 在这些情况下,悬停动作有效且数据表已呈现,但 CSS 未应用

有人可以帮忙吗??

提前致谢 迪帕克

【问题讨论】:

  • &lt;b&gt;&lt;/b&gt; 在 jQuery 选择器中做了什么?
  • 看看这个相关的answer
  • 只是一种格式...我只是试图让它变得粗体

标签: jquery jsf


【解决方案1】:

您需要选择生成的 HTML &lt;table&gt; 元素的客户端 ID,而不是 JSF &lt;h:dataTable&gt; 组件的组件 ID。在您的特定情况下,HTML ID 是 searchform:example。由于: 在 CSS 选择器中是非法字符,因此需要对其进行转义:

$("#searchform\\:example")

或使用属性选择器:

$("[id='searchform:example']")

更简单的方法是给 &lt;h:dataTable&gt; 一个样式类。

<h:dataTable styleClass="example">

在您的特定情况下,您已经拥有一个

<h:dataTable styleClass="display">

所以你也可以使用

$(".display")

【讨论】:

  • 哇哇哇,第一个选项确实很有魅力...非常感谢巴鲁... :) :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-16
  • 2012-07-02
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
  • 2018-07-23
相关资源
最近更新 更多