带有变量的jQuery选择器 [英] jQuery selectors with variables

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

问题描述

如何将变量与选择器混合?

How to mix variables with selectors?

我有ID变量.

我想从div #one中选择具有此ID的图像.

I want to select image with this id from div #one.

jQuery('#one img .id')是选择器.我已经尝试过$('#one img .'+id)但没有用.

jQuery('#one img .id') is the selector. I've tried $('#one img .'+id) but doesn't work.

推荐答案

根据下面的评论,您将使用以下内容:

Based on your comment below, you would use this:

$('#one img.'+id)

在您的问题中,您在img.class之间留有一个空格,我只是删除了该空格,以便得到img.classNameimg.'+className

In your question you have a space between img and the .class, I've simply removed that so you get img.className or img.'+className

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

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