[否匹配"消息jQuery用户界面自动完成 [英] "No Matches" message for jquery ui autocomplete

查看:196
本文介绍了[否匹配"消息jQuery用户界面自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的这一点,并看了看其他的例子,但我对如何设置自动完成的 http://docs.jquery.com/UI/Autocomplete 时,有没有结果。

这是code我使用,有人可以帮忙写休息,最好保持它点击一个建议页面。

 <脚本>
    $(文件)。就绪(函数(){
        VAR数据= [
            {标号:'雅虎',值:'http://yahoo.com},
            {标号:'宝马',值:'http://bmw.com},
            {标号:'兵',值:'http://bing.com'}
        ];
            $(#输入自动完成)。自动完成({
                来源:函数(请求,响应){
                变种结果= $ .ui.autocomplete.filter(数据,request.term);
                响应(results.slice(0,10))},
            重点:函数(事件,UI){
                $(event.target).VAL(ui.item.label);
                返回false;
            },
            选择:函数(事件,UI){
                $(event.target).VAL(ui.item.label);
                window.location的= ui.item.value;
                返回false;
            }
        });
    });
  < / SCRIPT>

先谢谢了。

更新:设法得到一个固定在一起,但我怎么能嵌入邮件中的一个工作链接

 <脚本类型=文/ JavaScript的'> //<![CDATA [
$(窗口).load(函数(){
        VAR数据= [
                {标号:'雅虎',值:'http://yahoo.com},
                {标号:'宝马',值:'http://bmw.com},
                {标号:'兵',值:'http://bing.com'}
        ];
                $(#输入自动完成)。自动完成({
                来源:函数(请求,响应){
                变种结果= $ .ui.autocomplete.filter(数据,request.term);
                如果(!results.length){
                            $(#无结果)文本。(< A HREF = \\/ \\>没有找到结果<!/ A>中);
                        }其他{
                            $(#无结果),空()。
                        }
                响应(results.slice(0,10));
                },
            重点:函数(事件,UI){
                $(event.target).VAL(ui.item.label);
                返回false;
            },
            选择:函数(事件,UI){
                $(event.target).VAL(ui.item.label);
                window.location的= ui.item.value;
                返回false;
            }
                });
    });
//]]>
  < / SCRIPT>


解决方案
而不是使用 $(#无结果)的

文本(< A HREF = \\/ \\&GT ;没有找到结果<!/ A>中)尝试 $(#无结果)HTML('< A HREF =>无结果发现<!/ A>')。虽然你为什么要与没有链接锚标签混淆了我。

I'm new to this and have looked at other examples but am unclear on how to set a "No Matches" messages for the latest version of autocomplete http://docs.jquery.com/UI/Autocomplete when there are no results.

This is the code I'm using, can someone help write the rest, ideally keeping it clickable to a 'suggestions' page.

<script>
    $(document).ready(function() {
        var data = [
            {label: 'Yahoo', value: 'http://yahoo.com'},
            {label: 'BMW', value: 'http://bmw.com'},
            {label: 'Bing', value: 'http://bing.com'}
        ]; 
            $("input#autocomplete").autocomplete({
                source: function(request, response) {
                var results = $.ui.autocomplete.filter(data, request.term);
                response(results.slice(0, 10))},            
            focus: function (event, ui) {
                $(event.target).val(ui.item.label);
                return false;
            },
            select: function (event, ui) {
                $(event.target).val(ui.item.label);
                window.location = ui.item.value;
                return false;
            }
        });
    });
  </script>

Thanks in advance.

UPDATE: Have managed to get a fix together, but how can I embed a working link within the message?

<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
        var data = [
                {label: 'Yahoo', value: 'http://yahoo.com'},
                {label: 'BMW', value: 'http://bmw.com'},
                {label: 'Bing', value: 'http://bing.com'}
        ]; 
                $("input#autocomplete").autocomplete({
                source: function(request, response) {
                var results = $.ui.autocomplete.filter(data, request.term);
                if (!results.length) {
                            $("#no-results").text("<a href=\"/\">No results found!</a>");
                        } else {
                            $("#no-results").empty();
                        }        
                response(results.slice(0, 10));
                },          
            focus: function (event, ui) {
                $(event.target).val(ui.item.label);
                return false;
            },
            select: function (event, ui) {
                $(event.target).val(ui.item.label);
                window.location = ui.item.value;
                return false;
            }               
                });
    });
//]]>  
  </script>

解决方案

Instead of using $("#no-results").text("<a href=\"/\">No results found!</a>") try $("#no-results").html('<a href="">No results found!</a>'). Although why you want an anchor tag with no link confuses me.

这篇关于[否匹配&QUOT;消息jQuery用户界面自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆