在JQuery函数中传递字符串参数

时间:2014-06-14 08:32:32

标签: jquery html

我正在处理以下代码:

function moveLeft() {
        if ($('#show-slider ul').is(":animated")) return;
        $('#show-slider ul').width(slideWidth*(slideCount+1))
        $('#show-slider ul li:last-child').clone().prependTo('#show-slider ul');

        $('#show-slider ul').css('left', - slideWidth).animate({'left': 0}, 333, function() {
            $('#show-slider ul').width(slideWidth*slideCount).css('left','');
            $('#show-slider ul li:last-child').remove();
        });
    };

$('.control_prev').click(function () {
        moveLeft();
    });

我想在 moveLeft()函数中将#show-slider 作为字符串传递。

我知道如何传递变量参数,如下所示:

var abc = '5';

function meraFunc(abc)
{
    alert(abc + " Some Text" );
}

$('#test').click(function() {
    meraFunc(abc);
});

这里是简短的小提琴 - http://jsfiddle.net/codestor/hxzd9/

这是我想要实现的目标:

function moveLeft() {
    // alert "#show-slider" in this line
    // alert "#show-slider ul" in this line
    // alert "#show-slider ul li" in this line
};

$('.control_prev').click(function () {
     moveLeft("#show-slider");
});

1 个答案:

答案 0 :(得分:0)

DEMO

使用此,

班级名称为control-prev,而非control_prev

$('.control-prev').click(function () {
     moveLeft("#show-slider");
});

function moveLeft(id) {
    alert(id);
    alert(id + ' ul');
    alert(id +' ul li');  
};
相关问题