使用变量:contains - 如何 [英] using a variable in :contains - how to

查看:82
本文介绍了使用变量:contains - 如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在电子商务网站上使用手风琴菜单。菜单保持打开状态,直到产品页面为止。在该页面上,我尝试使用面包屑来匹配菜单中的文本,然后应用一个类来打开菜单到页面的正确类别。

I am using accordion menu on an e-commerce site. The menu stays open with the options until the product page. On that page I am trying to use the breadcrumbs to match text in the menu and then apply a class to open the menu to the correct category for the page.

这是我的代码:

$(document).ready(function(){
 var bctext = $('#ProductBreadcrumb ul li:last-child').prev('li').children().text();
$('ul#accordion a:contains(bctext)').parent().parent().addClass('special');

 });

变量返回正确的文本,如果我输入匹配的字符串(番茄酱) :包含它就像我想要的那样工作并应用该类。但是,当我使用bctext变量时它不会工作。

The variable returns the correct text, and if I put a matching string ("Tomato Sauces") in the :contains it works just like I want it to and applies the class. However when I use bctext variable it wont work.

我也试过 a:contains($(bctext))它不起作用。这是我的语法吗?

I also tried a:contains($(bctext)) and it didn't work. Is it my syntax?

谢谢

推荐答案

尝试:

$('ul#accordion a:contains(' + bctext + ')')

这篇关于使用变量:contains - 如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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