Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/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 UI选项中使用$(this)_Jquery_Jquery Ui - Fatal编程技术网

在jQuery UI选项中使用$(this)

在jQuery UI选项中使用$(this),jquery,jquery-ui,Jquery,Jquery Ui,我有一种情况,我需要在position函数的选项中使用$(this)。我有两个下拉列表,每个下拉列表都需要位于相应按钮下方的中心位置。我不想在DOM中添加额外的ID或任何东西,因为这段代码将在一个页面中多次使用。这是一个例子 循环遍历每个元素,然后您将有权访问$(this): 阅读有关的更多信息。每个如下: 请考虑解释为什么在提问者的问题中这样做。由原始代码组成的答案可能证明你已经掌握了模式,但提问者(以及未来的读者)应该知道这是如何工作的以及为什么。@FrédéricHamidi我认为代码是不

我有一种情况,我需要在position函数的选项中使用$(this)。我有两个下拉列表,每个下拉列表都需要位于相应按钮下方的中心位置。我不想在DOM中添加额外的ID或任何东西,因为这段代码将在一个页面中多次使用。这是一个例子


循环遍历每个元素,然后您将有权访问
$(this)

阅读有关
的更多信息。每个
如下:


请考虑解释为什么在提问者的问题中这样做。由原始代码组成的答案可能证明你已经掌握了模式,但提问者(以及未来的读者)应该知道这是如何工作的以及为什么。@FrédéricHamidi我认为代码是不言自明的。不过我添加了一些评论。没关系,我理解它为什么有效。这是非常自我解释的。我会尽我所能接受的!谢谢你
$(".dropDown .dialogueBox").position({
    my:        "center top",
    at:        "center bottom",
    of:         $(this).parent().children(".drop-button"),
    collision: "none"
});
$(".dropDown .dialogueBox").each(function() {
    var that = $(this);
    that.position({
        my:        "center top",
        at:        "center bottom",
        of:         that.parent().children(".drop-button"),
        collision: "none"
    });
});