javascript - 在 JSF panelgrid 上使用 jQuery onmousedown 和 onmouseup

标签 javascript jquery jsf jsf-2

我在页面上同时使用 jQuery 和 JSF 元素。

我的要求是 panelGrid 元素在单击时重定向用户。 我通过执行以下操作实现了这一目标:

    <h:panelGrid>
    <f:ajax event="click" listener="#{bean.click"/>
    <h:panelGroup>
        <div>
            <h:panelGroup>
                <img src="../resources/img/icon_circle_footer.png" width="20px" height="20px" />
                <div>
                    <div>
                        <div><b>R800,00</b></div>
                        <div>per passenger</div>
                    </div>
                    <div>Company Name</div>
                </div>
                <div>
                    <div>
                        <div>Timespan</div>
                        <div>non-stop</div>
                    </div>
                </div>
                <img src="../resources/img/icon_circle_footer.png" width="20px" height="20px" />
            </h:panelGroup>
        </div>
    </h:panelGroup>
</h:panelGrid>

这工作得很好,但目前没有任何东西可以向用户表明该元素已被单击。

我想在用户单击元素时更改元素的背景,并尝试了以下操作:

<h:panelGrid onmousedown="mousedown(this);" onmouseup="mouseup(this);">
    <f:ajax event="click" listener="#{bean.clickGrid}"
</h:panelGrid>

<script>
    function mousedown(element) {
        element.toggleClass("hilite");
    }

    function mouseup(element) {
        element.toggleClass("hilite");
    }
</script>

当单击该元素时,JS 会中断并将其记录到控制台:Uncaught TypeError: Object #<HTMLTableElement> as no method 'toggleClass' 。我理解这个问题,但我已经搜索了可以应用于表元素的类似方法,但没有运气。

大家有什么想法吗?

最佳答案

是的,DOM 对象没有toggleClass 方法,它是您尝试调用它们的jQuery 方法。

如果您包含 jQuery,那么这将是解决方案:

$(element).toggleClass("hilite");

关于javascript - 在 JSF panelgrid 上使用 jQuery onmousedown 和 onmouseup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18789061/

相关文章:

javascript - 为什么两个变量都是 JQuery 对象,而 .css 属性却对其中一个不起作用?

jquery - 仅 IE 9 setSelection 中的错误不会滚动到所选行

java - Icefaces 2 插件问题

jsf - java.lang.UnsupportedOperationException : getRowData(String rowKey) must be implemented when basic rowKey algorithm is not used

javascript - 如何给上传为 FormData 的 Blob 一个文件名?

javascript - HTML DIV 作为另一个 DIV 的背景

javascript - jQuery 中的空输入框 onclick

JSF: session 作用域托管 bean 的属性变为空

javascript - babel-loader jsx 语法错误 : Unexpected token

javascript - JS 函数与我的 if 语句逻辑不匹配