将jQuery与JSF自动生成的id一起使用(问题为":")

rsi*_*deb 3 jquery jsf

我读了这篇文章在CSS选择器中处理元素ID中的冒号,其中概述了如何选择包含冒号的已知id.

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

Ple*_*and 5

使用jQuery 迭代每个单独的img元素.假设你的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);
    }
});
Run Code Online (Sandbox Code Playgroud)