【问题标题】:How to get the value from li element in query如何从查询中的li元素中获取值
【发布时间】:2013-07-27 16:14:46
【问题描述】:

xhtml:

<ul class="groupsWrapper">
    <ui:repeat value="#{connectDashBoardBean.groups}" var="group">
        <ui:fragment rendered="#{group.activeGroup}">
            <li class="group titleToolTip chooseSubGroup" title="Click To Choose">
                <div style="display: none;" class="groupId">#{group.groupId}</div>
                <div class="groupContainer">
                    <div class="groupImage" style="float:left;color: #fff">
                        <h:graphicImage value="#{group.groupIconPath}" height="70" width="70"/>
                    </div>
                    <div class="groupContent" style="display:inline-block;padding: 0;word-wrap: break-word;font-weight: bold;">
                        <h:outputText value="#{group.groupName}"/>
                    </div>
                    <!-- <div class="groupTotalSubGroup" style="display:block;padding: 0;word-wrap: break-word;">
                        <h:outputText value="Sub Group:#{group.totalSubGroup}"/>
                    </div> -->
                    <div class="groupFollower" style="display:block;padding: 0;word-wrap: break-word;">
                        <h:outputText value="Followers:#{group.totalFollower}"/>
                    </div>
                    <div class="activeThread" style="display:block;padding: 0;word-wrap: break-word;">
                        <h:outputText value="Active Thread:#{group.totalActiveThread}"/>
                    </div>
                </div>
            </li>
        </ui:fragment>
    </ui:repeat>
</ul>

jquery:

var group = $(this).find('.groupId').text();

总是让我空空如也,我试过text()html()val()

我在 ajax 调用的 .tooltipster() 中使用这个选择器

$('.chooseSubGroup').tooltipster({

    content: 'Loading...',
    functionBefore: function (origin, continueTooltip) {

        // we'll make this function asynchronous and allow the
        // tooltip to go ahead and show the loading notification
        // while fetching our data
        continueTooltip();

        // next, we want to check if our data has already been
        // cached
        if (origin.data('ajax') !== 'cached') {
            var group = $(this).find('.groupId').text();
            alert(group);
            $.ajax({
                type: 'GET',
                url: 'tooltip/sub_group_tooltip.xhtml?groupId=' + group,
                data: {
                    groupId: group
                },
                success: function (data) {
                    // update our tooltip content with our returned
                    // data and cache it
                    origin.tooltipster('update', data).data('ajax',
                        'cached');
                }
            });
        }
    },
    interactive: true,
    interactiveTolerance: 350,
    onlyOne: true,
    theme: '.tooltip-theme',
    trigger: 'click',
    updateAnimation: true,
    arrow: true,
    position: 'right',
    delay: 500
});

请告诉我如何获得隐藏 div 的值?

提前致谢

【问题讨论】:

  • 嗯,根据您的代码,我看不出有什么问题。请console.log($(this)) 告诉我返回了什么?
  • JSF 与这个问题无关。 jQuery 不适用于 JSF。相反,它适用于 JSF 生成的 HTML 输出。为了从[jquery] 用户那里得到更好的答案,您应该从问题中删除不相关的 JSF 信息,并将其替换为 JSF 生成的 HTML 输出(并将 [jsf-2] 标记替换为 [html])。
  • @Ohgodwhy:我尝试使用控制台日志,输出:[Object {animation="fade", arrow=true, ...}],这不过是提供 tooltip.may 的属性是它没有规定
  • 元素,有什么解决方法吗?
  • @Ohgodwhy:谢谢你的观点,现在我暂时应用了像 :var groupId; 这样的工作。和 $('.chooseSubGroup').click(function() { groupId = $(this).find('.groupId').text(); });最后在工具提示函数中使用该变量,有更好的解决方案吗?
  • 标签: jquery jsf-2 tooltip


    【解决方案1】:

    工具提示将其对象返回为$(this)。解决方法是

    $('.chooseSubGroup').each(function(){
        var $this = $(this);
        $this.tooltipster({
            //other code
            if (origin.data('ajax') !== 'cached') {
            var group = $this.find('.groupId').text();  //note, $this, not $(this)
        });
    });
    

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        相关资源
        最近更新 更多
        热门标签