jQuery 自动完成禁用使自动完成部分透明,而不是禁用
我在我的网站上使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚添加了一个 CSS 规则来显示:隐藏自动完成框。没什么大不了的。
Just added a CSS rule to display:hidden the autocomplete box. No biggie.