如何在jquery中引用JSF组件ID? [英] How to refer to a JSF component Id in jquery?

查看:74
本文介绍了如何在jquery中引用JSF组件ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在jquery中引用JSF组件,因为我不知道要添加到要引用的组件ID的ID?

How do I refer to JSF components in jquery, as I dont know the id(s) prepended to the id of component I want to refer ?

推荐答案

您可以提供所有

You can give all NamingContainer components in the view such as <h:form>, <h:dataTable>, <ui:repeat>, <my:composite> a fixed ID so that the HTML-generated client ID is safely predictable. If you're uncertain, just open the page in webbrowser, rightclick and do View Source. If you see an autogenerated ID like j_id123 in the client ID chain, then you need to give exactly that component a fixed ID.

或者,您可以使用#{component.clientId}让EL将组件的客户端ID打印到生成的HTML输出中.您可以使用组件的binding属性将组件绑定到视图.像这样:

Alternatively, you can use #{component.clientId} to let EL print the component's client ID to the generated HTML output. You can use component's binding attribute to bind the component to the view. Something like this:

<h:inputText binding="#{foo}" />
<script>
    var $foo = $("[id='#{foo.clientId}']"); // jQuery will then escape ":".
    // ...
</script>

这仅要求脚本是视图文件的一部分.

This only requires that the script is part of the view file.

作为另一种选择,您可以给有问题的元素一个类名:

As another alternative, you could give the element in question a classname:

<h:inputText styleClass="foo" />
<script>
    var $foo = $(".foo");
    // ...
</script>

作为另一种选择,您可以将HTML DOM元素本身传递给函数:

As again another alternative, you could just pass the HTML DOM element itself into the function:

<h:inputText onclick="foo(this)" />
<script>
    function foo(element) {
        var $element = $(element);
        // ...
    }
</script>

这篇关于如何在jquery中引用JSF组件ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆