Javascript表单操作

Javascript表单操作,javascript,html,forms,autocomplete,Javascript,Html,Forms,Autocomplete,我的页面上有一个文本字段,该字段具有自动完成功能,以数据库中的项目为特征。选中此选项后,使用jquery将页面滚动到页面上的结果位置。我希望表单滚动到“提交结果”按钮,而不必再次单击文本字段。如何编辑代码,使其在提交时发生,而不是在文本字段单击时发生 表格代码- <form autocomplete="off"> <form name="search-highlight" id="search-highlight" method="post" action="#"> &l

我的页面上有一个文本字段,该字段具有自动完成功能,以数据库中的项目为特征。选中此选项后,使用jquery将页面滚动到页面上的结果位置。我希望表单滚动到“提交结果”按钮,而不必再次单击文本字段。如何编辑代码,使其在提交时发生,而不是在文本字段单击时发生

表格代码-

<form autocomplete="off">
<form name="search-highlight" id="search-highlight" method="post" action="#">
<p>
Film Name <label>:</label>
<input type="text" name="scroll" id="scroll" class="scroll"/>
                       <!--input type="button" value="Get Value" /-->
 </p>
<input type="submit" value="find" />
</form>


电影名称:

还有javascript

$("#scroll").autocomplete("get_film_list.php", {
    width: 260,
    matchContains: true,
    //mustMatch: true,
    //minChars: 0,
    //multiple: true,
    //highlight: false,
    //multipleSeparator: ",",
    selectFirst: false
});


$("#scroll").click(function(){  

    // start variables as empty  
    var scroll = "";  
    var n = "0";  

    // hide the results at first  
    $("p.results").hide().empty();  
    // grab the input value and store in variable  
    scroll = $('#scroll').attr('value');  
    console.log("The value of film is: "+scroll);  

    $('span.highlight').each(function(){  
        $(this).after($(this).html()).remove();  
    });  

    if($('#scroll').val() == ""){  
        $("p.results").fadeIn().append("Enter film in field above");  
        $('#scroll').fadeIn().addClass("error");  
        return false;  
    }else{  
       $('div.timeline :contains("'+scroll+'")').each(function(){ 
           $(this).html($(this).html().replace(new RegExp(scroll,'g'), '<span class="highlight">'+scroll+'</span>'));  
           $(this).find('span.highlight').fadeIn("slow"); 
           var offset = $(this).offset().top
           $('html,body').animate({scrollTop: offset}, 2000);
           return false;

        });  

        // how many did it find?  
        n = $("span.highlight").length;  
        console.log("There is a total of: "+n);  

        if(n == 0){  
            $("p.results").fadeIn().append("No results were returned");  
        }else{  
            $("p.results").fadeIn().append("<strong>Returned:</strong> "+n+" result(s) for: <em><strong>"+scroll+"</strong></em>.");  
        }  
        return false;  
    }  
});  
});
$(“#滚动”).autocomplete(“get#film_list.php”{
宽度:260,
对,,
//mustMatch:是的,
//明查斯:0,
//多重:对,
//推荐理由:错,
//多重分隔符:“,”,
selectFirst:false
});
$(“#滚动”)。单击(函数(){
//将变量启动为空
var=”;
var n=“0”;
//首先隐藏结果
$(“p.results”).hide().empty();
//获取输入值并存储在变量中
滚动=$('#滚动').attr('value');
console.log(“胶片的值为:”+滚动);
$('span.highlight')。每个(函数(){
$(this).after($(this.html()).remove();
});  
如果($('#滚动“).val()==”){
$(“p.results”).fadeIn().append(“在上面的字段中输入胶片”);
$(“#滚动”).fadeIn().addClass(“错误”);
返回false;
}否则{
$('div.timeline:包含(“+scroll+”)。每个(函数(){
$(this.html($(this.html().replace)(新的RegExp(scroll,'g'),''+scroll+'');
$(this.find('span.highlight').fadeIn(“slow”);
var offset=$(this).offset().top
$('html,body').animate({scrollTop:offset},2000);
返回false;
});  
//找到了多少?
n=$(“span.highlight”).长度;
console.log(“总共有:”+n);
如果(n==0){
$(“p.results”).fadeIn().append(“未返回任何结果”);
}否则{
$(“p.results”).fadeIn();
}  
返回false;
}  
});  
});
我希望你能理解我的问题-如果不是,这里有一个演示(未优化)www.ignettathedesign.com/CheckFilm/index.php

如果您更改
$(“#滚动”)。请单击(
)以指向提交按钮(类似于
$(“#搜索突出显示输入[type='submit'])。单击应获得该行为

您可能应该扩展click回调的签名以包含事件参数,如中所示


.click(function(event)){
这样以后你就可以调用
event.stopPropagation()
,向浏览器表明你输入的click事件已经被处理(并且它不会试图将表单发回)。

演示页面中的jQuery没有定义吗?