用于跨度内跨度的 CSS 或 jQuery 选择器

发布于 2024-12-04 10:37:46 字数 1046 浏览 0 评论 0原文

我正在尝试使用纯 CSS 或 JQuery 选择器在 div 内的跨度内选择一个跨度。 html 如下:

<div id="example2_paginate" class="dataTables_paginate paging_full_numbers">
<span id="example2_first" class="first paginate_button paginate_button_disabled">First</span>
<span id="example2_previous" class="previous paginate_button paginate_button_disabled">Previous</span>
<span>
<span class="paginate_active">1</span>
<span class="paginate_button">2</span>
<span class="paginate_button">3</span>
<span class="paginate_button">4</span>
<span class="paginate_button">5</span>
</span>
<span id="example2_next" class="next paginate_button">Next</span>
<span id="example2_last" class="last paginate_button">Last</span>
</div>

我想选择包含 1 到 5(paginate_active 和 5 个分页按钮)的跨度,单独。

由于我对 CSS 和 jQuery 的了解非常有限,我尝试了几种但我确信我的语法是错误的,例如 $("paging_full_numbers span:eq(1)")

您能否给我一个提示,告诉我如何去做?

I am trying to select a span within a span within a div using plain CSS or JQuery selectors. The html is as follows:

<div id="example2_paginate" class="dataTables_paginate paging_full_numbers">
<span id="example2_first" class="first paginate_button paginate_button_disabled">First</span>
<span id="example2_previous" class="previous paginate_button paginate_button_disabled">Previous</span>
<span>
<span class="paginate_active">1</span>
<span class="paginate_button">2</span>
<span class="paginate_button">3</span>
<span class="paginate_button">4</span>
<span class="paginate_button">5</span>
</span>
<span id="example2_next" class="next paginate_button">Next</span>
<span id="example2_last" class="last paginate_button">Last</span>
</div>

I want to select spans that contain 1 to 5 (paginate_active and the 5 paginate buttons), individually.

With my very limited knowledge of CSS and jQuery I've tried a couple of things but I'm sure my syntax is wrong, like $("paging_full_numbers span:eq(1)") .

Could you please give me a hint of how to go about it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦里寻她 2024-12-11 10:37:46

要单独选择它们,您可以简单地选择它们,然后使用 jQuerys .each()。例如

spanList = $('#example2_paginate').find('.paginate_active, .paginate_button');

将查找 id 元素内的所有 'paginate_active' 或 'paginate_button' 类= example2_paginate。然后你可以写:

 spanList.each(function(index){
    <-- code here for occurence of index index-->
});

或者选择第 i 个按钮而不循环遍历所有按钮:

spanList.eq(i)

参见 jsFiddle:http://jsfiddle。净/t4KWr/

To select them individually, you can simply select them all and then use jQuerys .each(). For example

spanList = $('#example2_paginate').find('.paginate_active, .paginate_button');

will find all classes of 'paginate_active' or 'paginate_button' that, are inside your element of id=example2_paginate. Then you can write:

 spanList.each(function(index){
    <-- code here for occurence of index index-->
});

Alternatively to select the i^th button without looping through them all:

spanList.eq(i)

See jsFiddle: http://jsfiddle.net/t4KWr/

东京女 2024-12-11 10:37:46

这个CSS就是你想要的。

div.paging_full_numbers > span > span.paginate_active, div.paging_full_numbers > span > span.paginate_button

This CSS is what you want.

div.paging_full_numbers > span > span.paginate_active, div.paging_full_numbers > span > span.paginate_button
﹎☆浅夏丿初晴 2024-12-11 10:37:46

例如,获取 5 个跨度中的第三个的快速方法是:

$(".paging_full_numbers > span > span:nth-child(3)")

A quick way to get, say, the third of the 5 spans would be:

$(".paging_full_numbers > span > span:nth-child(3)")
初见终念 2024-12-11 10:37:46

似乎有一个问题

$("paging_full_numbers span:eq(1)")

You should write like

$("#paging_full_numbers span:eq(1)")

或者 if you are using class

 $(".paging_full_numbers span:eq(1)")

its seem that there is a problem with

$("paging_full_numbers span:eq(1)")

You should write like

$("#paging_full_numbers span:eq(1)")

Or if you are using class

 $(".paging_full_numbers span:eq(1)")
似梦非梦 2024-12-11 10:37:46

此选择包含 1 到 5 个范围(paginate_active 和 5 个分页按钮)的范围,分别:

$("div.paging_full_numbers span:[class='paginate_active'],[class='paginate_button']").each(function(){
    //do what you want here
});

选择仅包含“paginate_active”类或仅包含“paginate_button”类的范围

This select spans that contain 1 to 5 (paginate_active and the 5 paginate buttons), individually:

$("div.paging_full_numbers span:[class='paginate_active'],[class='paginate_button']").each(function(){
    //do what you want here
});

That select the span's with only class 'paginate_active' or only class 'paginate_button'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文