本文介绍了将变量与jquery选择器一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下几行代码,我想使用visibleoffer
变量作为选择器.如何连接它?
I have following lines of code and I want to use visibleoffer
variable as selector. How can I concatenate it?
var visibleoffer = '.' + obj.parents('tbody').attr('providername') + ' .visible-offers'; //visibleoffer = .Txy .visible-offers
$(obj).parents('.Provider').find(".Offers:not(.HideByProviderFilter,.HideByMainFilter,.HideByProviderFilter.HideByMainFilter,+ visibleoffer)").length;
它变成:
$(obj).parents('.Provider').find(".Offers:not(.HideByProviderFilter,.HideByMainFilter,.HideByProviderFilter.HideByMainFilter,.Txy .visible-offers)").length;
推荐答案
在构建选择器字符串时,您需要连接变量:
You need to concatenate variable while building selector string:
$(obj).parents('.Provider').find(".Offers:not(.HideByProviderFilter,.HideByMainFilter,.HideByProviderFilter.HideByMainFilter," + visibleoffer +")").length;
这篇关于将变量与jquery选择器一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!