我读了这篇文章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/