【问题标题】:Autocompete search as the value of inputs changes随着输入值的变化自动完成搜索
【发布时间】:2012-08-16 14:13:29
【问题描述】:

我有一个类似的搜索表单 -

image here

我想要做的是使用 jquery 和 php 来获得结果,因为用户更改了任何表单元素的值,但我只能在所有表单元素都被视为单个并且没有其他选项时才能这样做.但我想在任何表单值发生变化时触发偶数。

google.load("jquery", "1.3.1");
google.setOnLoadCallback(function()
{
    // Safely inject CSS3 and give the search results a shadow
    var cssObj = { 'box-shadow' : '#888 5px 10px 10px', // Added when CSS3 is standard
        '-webkit-box-shadow' : '#888 5px 10px 10px', // Safari
        '-moz-box-shadow' : '#888 5px 10px 10px'}; // Firefox 3.5+
    $("#suggestions").css(cssObj);

    // Fade out the suggestions box when not active
     /*$("input").blur(function(){
        $('#suggestions').fadeOut();
     });*/
});

function lookup(inputString) {
    if(inputString.length == 0) {
        $('#suggestions').fadeOut(); // Hide the suggestions box
    } else {
        $.post("regularsearch.php", {queryString: ""+inputString+""}, function(data) { // Do an AJAX call
            $('#suggestions').fadeIn(); // Show the suggestions box
            $('#suggestions').html(data); // Fill the suggestions box
        });
    }
}

上面是我的一个元素搜索的 jquery。如何一次搜索全部?

【问题讨论】:

    标签: jquery forms search input


    【解决方案1】:

    这是我编写的一个 jquery 插件,可以帮助您解决问题。它使用 ajax 作为用户类型从服务器检索数据。

    http://jsfiddle.net/alforno/g4stL/

    【讨论】:

    • 你所展示的就是我所要求的没有任何补充
    • 如果我的理解正确,那么您将需要定义一个函数来获取所有搜索输入的值并触发搜索,然后将该函数分配为每个输入控件值更改的事件处理程序事件。
    • 如果您看过图片,那么您知道有很多输入,例如单选按钮和选择以及文本类型,所以我希望如果用户更改任何该值的值,则可以触发并检索数据来自 mysql 数据库而不刷新页面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-20
    • 2023-01-20
    • 1970-01-01
    • 2018-06-08
    相关资源
    最近更新 更多