jQuery 自动完成禁用使自动完成部分透明,而不是禁用

发布于 2024-08-29 22:36:30 字数 1183 浏览 4 评论 0原文

我在我的网站上使用 jQuery UI 的“自动完成”功能进行搜索。当您将单选按钮从“区域搜索”更改为“名称搜索”时,我希望它禁用自动完成功能,并在您切换回来时重新启用它。但是,当您禁用自动完成功能时,它不会隐藏下拉列表,它只需将其调暗至 20% 左右即可。这是我的 javascript:

var allFields = new Array(<?php echo $allFields ?>);

$(document).ready(function() {

    if ($("input[name='searchType']:checked").val() == 'areaCode') {
        $("#siteSearch").autocomplete({
            source: allFields,
            minLength: 2
        });
    }

    $("input[name='searchType']").change(function(){
        if ($("input[name='searchType']:checked").val() == 'areaCode') {
            $( "#siteSearch" ).autocomplete( "option", "disabled", false );
            alert("enabled");
        }
        else {
            $( "#siteSearch" ).autocomplete( "option", "disabled", true );
            alert("disabled");
        }

    });

});

您可以在 http://crewinyourcode.com

首先您必须选择要搜索的区号,然后您可以看到问题

: 我意识到您必须先选择区号,然后才能选择切换搜索类型。如果您访问此 URL,您将立即获得它们: http://crewinyourcode.com/search/choose-category/732/

I'm using the jQuery UI's "autocomplete" function on a search on my site. When you change a radio button from 'area search" to "name search" I want it to disable the autocomplete, and re-enable it when you switch back. However, when you disable the autocomplete it doesn't hide the dropdown, it just dims it to 20% opacity or so. Here's my javascript:

var allFields = new Array(<?php echo $allFields ?>);

$(document).ready(function() {

    if ($("input[name='searchType']:checked").val() == 'areaCode') {
        $("#siteSearch").autocomplete({
            source: allFields,
            minLength: 2
        });
    }

    $("input[name='searchType']").change(function(){
        if ($("input[name='searchType']:checked").val() == 'areaCode') {
            $( "#siteSearch" ).autocomplete( "option", "disabled", false );
            alert("enabled");
        }
        else {
            $( "#siteSearch" ).autocomplete( "option", "disabled", true );
            alert("disabled");
        }

    });

});

You can see it happening at http://crewinyourcode.com

First you have to chose an area code to search, and then you can see the issue.

EDIT:
I realize you have to choose an area code before you're given the option to switch search types. If you go to this URL you'll have both of them immediately:
http://crewinyourcode.com/search/choose-category/732/

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

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

发布评论

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

评论(1

早乙女 2024-09-05 22:36:30

刚刚添加了一个 CSS 规则来显示:隐藏自动完成框。没什么大不了的。

Just added a CSS rule to display:hidden the autocomplete box. No biggie.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文