将var放入jquery:gt() [英] Put var inside jquery :gt()

查看:68
本文介绍了将var放入jquery:gt()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设置为display:none的列表和一些显示第3项的代码:

I have a list set with display:none and some code to show item 3:

HTML:

<ul>
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
    <li>item 4</li>
</ul>

jquery:

var item = '1';

$("li:gt(1):lt(1)").show();

是否可以在gt选择中获取var?我能想到的是这个

Is it possible to get the var inside the gt selection? Al I can think of is this

$("li:gt('+item+'):lt(1)").show();

不起作用. 能做到吗?如果没有,我还能尝试什么?

Doesn't work. Can this be done? If not what else can I try?

示例: http://jsfiddle.net/BSakQ/5/

推荐答案

您需要使用正确的引号分隔字符串.试试这个:

You need to delimit the string with the correct quotes. Try this:

$("li:gt(" + item + "):lt(1)").show();

这篇关于将var放入jquery:gt()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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