强制 jQuery UI 自动完成移动?

发布于 2024-09-27 00:01:57 字数 432 浏览 0 评论 0原文

我在我的网站上使用 jQuery UI 的自动完成功能,并且工作正常,但我正在重新设计系统,所以我需要进行这一更改。目前,自动完成功能在输入的底部打开。但是,无论是使用 jQuery 还是 CSS,我都无法将其强制到自定义位置。

我已经尝试过:

    $('#search').autocomplete('widget').css({
        'margin-left': -200
        //or
        left: 200
    });

我也尝试添加 !important 到规则中,但没有影响。

我还尝试将 css 添加到 .ui-autocomplete 中,但没有任何结果。

似乎当盒子打开时,它会覆盖所有这些更改。对此有什么想法吗?我真的需要一个解决方案。

谢谢, 马蒂·莱恩

I'm using autocomplete from jQuery UI on my website, and it's working fine, but I'm redesigning the system, so I need to make this one change. Currently, the autocomplete opens on the bottom of the input. However, I can't force it to a custom position, neither with jQuery or CSS.

I've tried this:

    $('#search').autocomplete('widget').css({
        'margin-left': -200
        //or
        left: 200
    });

I also tried adding !important to tthe rules but no affect.

I've also tried to add css to .ui-autocomplete, without any result.

It seems that when the box opens, it overwrites all these changes. Any idea about this? I'm really in need of a solution.

Thanks,
Martti Laine

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一人独醉 2024-10-04 00:01:57

您可以为 open() 提供一个可选函数来执行此操作:

示例:

 $("#search").autocomplete({ 
                            open: function(event, ui) 
                                  {$(this).next().css('left',
                                    function(index, value) {return 200+parseInt(value)});
                                  }
    });

...将位置设置为正常位置左侧 200px

You can provide an optional function for open() to do this:

Example:

 $("#search").autocomplete({ 
                            open: function(event, ui) 
                                  {$(this).next().css('left',
                                    function(index, value) {return 200+parseInt(value)});
                                  }
    });

...will set the position to 200px left of the position it would have been normally

感受沵的脚步 2024-10-04 00:01:57

我的自动完成功能在 DOM 末尾打开。根本不接近触发输入...
我正在考虑查看触发输入的索引,然后找到自动完成的相应索引,但我不知道为什么 - 它对我来说似乎不够强大。

My autocomplete opens at the end of the DOM. Not close at all to the trigger input...
I'm thinking of looking at the index of triggering input, and then finding the autocomplete's corresponding index, but i don't know why- its seems not robust enough for me.

最后的乘客 2024-10-04 00:01:57

与 NeoSwf 一样,我发现我的自动完成功能被插入到 DOM 底部附近。依赖$(this).next()发现它很脆弱。我建议使用更具体的内容,例如 'ul.ui-autocomplete',而不是 this。这是我的版本的 CoffeeScript:

jQuery ->
  $('#search').autocomplete
    open: (event, ui) ->
      $('ul.ui-autocomplete').css('left', (index, value) ->
        return 200 + parseInt(value))

Like NeoSwf, I found that my autocomplete was being inserted near the bottom of the DOM. Depending on $(this).next() to find it is fragile. Instead of this, I recommend using something more specific like 'ul.ui-autocomplete'. Here's the CoffeeScript for my version:

jQuery ->
  $('#search').autocomplete
    open: (event, ui) ->
      $('ul.ui-autocomplete').css('left', (index, value) ->
        return 200 + parseInt(value))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文