问题
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;
So it becomes:
$(obj).parents('.Provider').find(".Offers:not(.HideByProviderFilter,.HideByMainFilter,.HideByProviderFilter.HideByMainFilter,.Txy .visible-offers)").length;
回答1:
You need to concatenate variable while building selector string:
$(obj).parents('.Provider').find(".Offers:not(.HideByProviderFilter,.HideByMainFilter,.HideByProviderFilter.HideByMainFilter," + visibleoffer +")").length;
来源:https://stackoverflow.com/questions/38350684/using-variable-with-jquery-selector