jQuery通过内部文本选择 [英] JQuery select by inner text

查看:66
本文介绍了jQuery通过内部文本选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个具有全日历的项目,我需要能够根据日期选择一个元素.这是我需要选择的元素的示例:

I am doing a project with fullcalendar and I need to be able to select an element based on the day number. Here is a sample of the element I need to select:

<div class=​"fc-day-number">​1​</div>​

这是我写的javascript:

Here is the javascript I have written:

$("div.fc-day-number:contains(" + day + ")").parent().parent().css({ 'background-color': 'Green' });

这将获取其内部文本包含day变量的所有div,问题是,如果day == 1则还选择11,12,13,21,31,依此类推.我该如何编写一个JQuery选择器,该选择器将使用类"fc-day-number"来抓取其内部文本与day完全相同的div?

This will grab all the divs whose inner text contains the day variable, problem is if day==1 then it also selects 11,12,13,21,31,etc. How do I write a JQuery selector that will grab the divs with class "fc-day-number" and whose inner text is exactly equal to day?

推荐答案

编写您自己的filter函数:

Write your own filter function:

$("div.fc-day-number").filter(function (){
    return $(this).text() == day;
}).parent().parent().css({ 'background-color': 'Green' });

这篇关于jQuery通过内部文本选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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