jquery - 将 jQuery 与 JSF 自动生成的 id 结合使用(问题为 ":")

标签 jquery jsf

我读了这篇文章Handling a colon in an element ID in a CSS selector其中概述了如何选择包含冒号的已知 id。

我想做的是创建一个包含图像的 JSF 列表。然后使用 jQuery 我想选择每个图像并读取 id。如果不编写一些代码来替换冒号,这可能吗?

最佳答案

使用 jQuery 来iterate over each individual img element 。假设您的 ul 元素的 ID 为 wx:yz:

// Use jQuery to select all images within
var imgs = $('#wx\\:yz img');

// Iterate over each one and give the image ID to the library
// only if the image actually has an ID.
imgs.each(function() {
    if(this.id && this.id.length) {
        nameOfYourLibraryFunction(this.id);
    }
});

关于jquery - 将 jQuery 与 JSF 自动生成的 id 结合使用(问题为 ":"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4189012/

相关文章:

jquery - 使用客户端验证生成 Openerp 二维码

javascript - jQuery : TypeError: invalid 'in' operand a

jsf - 添加 <f :validateLength> tag customised for a field 的错误消息

jsf - primefaces blockui 不隐藏

javascript - 自动更改可点击幻灯片顶部的 div 的文本颜色

jquery - 如何在Fancybox中为没有链接的图像设置组?

jquery - 如何在乘法和除法中保持小数精度(在 jQuery、javascript 中)?

java - 在同一个 Tomcat 服务器上部署 JSF 1.2 和 JSF 2.0 应用程序

java - 复合组件的 ManagedBean

jsf - 将 JSF Managed Beans 转换为 CDI Beans