Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
组合变量和字符串的JQuery_Jquery_Variables_Concatenation - Fatal编程技术网

组合变量和字符串的JQuery

组合变量和字符串的JQuery,jquery,variables,concatenation,Jquery,Variables,Concatenation,我正在尝试进行以下工作,但不知道如何将变量与字符串组合。我已经在下面评论了我不理解的地方 谢谢大家! $('.mcTransferGroup').each(function() { var mcAdd = $(this).find('#mcAdd'); var mcRemove = $(this).find('#mcRemove'); var mcSelect1 = $(this).find('.mcSelect1'); var mcSelect2 = $(thi

我正在尝试进行以下工作,但不知道如何将变量与字符串组合。我已经在下面评论了我不理解的地方

谢谢大家!

$('.mcTransferGroup').each(function() {
    var mcAdd = $(this).find('#mcAdd');
    var mcRemove = $(this).find('#mcRemove');
    var mcSelect1 = $(this).find('.mcSelect1');
    var mcSelect2 = $(this).find('.mcSelect2');

    $(mcAdd).click(function() {
        // below here
        $(mcSelect1, 'option:selected').remove().appendTo(mcSelect2);
    });
    $(mcRemove).click(function() {
        // and here ...
        $(mcSelect2, 'option:selected').remove().appendTo(mcSelect1);
    });
});
使用(用于查找给定元素中的元素)和(用于筛选现有jQuery选择)。

请尝试,例如:

$('option:selected', mcSelect1).remove().appendTo(mcSelect2);
上下文应该是第二个参数


下面是一个示例:

为什么
在事件处理程序中返回
?但是如何将变量与筛选器组合?手册中没有说明。如果mcSelect1是select标记,请使用mcSelect1.find(“…”)。如果它已经是选项集合(我不能确定它是什么,因为您没有提供HTML代码)-使用mcSelect1.filter(“…”)。