Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 搜索表单没有';t提交_Javascript_Jquery - Fatal编程技术网

Javascript 搜索表单没有';t提交

Javascript 搜索表单没有';t提交,javascript,jquery,Javascript,Jquery,我有这个搜索表: 它不会屈服。当我点击进入或搜索图标时。为什么? <form action="/search.php" method="get"> <fieldset> <ul class="toolbar clearfix"> <li><button type="submit" id="btn-search"><span class="fa fa-search" style="c

我有这个搜索表:

它不会屈服。当我点击进入或搜索图标时。为什么?

<form action="/search.php" method="get">
    <fieldset>
        <ul class="toolbar clearfix">
            <li><button type="submit" id="btn-search"><span class="fa fa-search" style="color:gray;"></span></button></li>
            <li><input type="search" id="search" placeholder="" name="s"></li>
        </ul>
    </fieldset>
</form>

$(document).ready(function() {
    $('#btn-search').on('click', function(e) {
        e.preventDefault();
        $('#search').fadeIn().focus();
    });
});

$(文档).ready(函数(){ $(“#btn搜索”)。在('click',函数(e)上{ e、 预防默认值(); $(“#搜索”).fadeIn().focus(); }); });
因为您正在使用
e.preventDefault()阻止表单提交。
不使用任何其他方法提交表格。
您可以使用ajax提交表单,如下所示:

$('#btn-search').on('click', function(e) {
        e.preventDefault();

        if( $('#search').val() ){
            $.ajax({
                url     : 'submit.php',
                data    : { 'input': $('#search').val() },
                success : function( response ) {
                    alert( response );
                }
            });
        }

        $('#search').animate({
            width: 'toggle',
        }).focus();
    });
<?php 
    echo "You have entered: " . $_GET['input'];
?>
并在
submit.php

submit.php
中,您可以编写用户输入所需的内容。大概是这样的:

$('#btn-search').on('click', function(e) {
        e.preventDefault();

        if( $('#search').val() ){
            $.ajax({
                url     : 'submit.php',
                data    : { 'input': $('#search').val() },
                success : function( response ) {
                    alert( response );
                }
            });
        }

        $('#search').animate({
            width: 'toggle',
        }).focus();
    });
<?php 
    echo "You have entered: " . $_GET['input'];
?>


希望这有帮助。

因为您告诉它与
e.preventDefault()无关