简体   繁体   English

HTML发布时提交的特定值

[英]HTML post specific value on submit

I have a search bar and I'm trying to intercept the POST, append "tag:", and then submit it so if someone types "apple" in the search bar it comes out tag:apple 我有一个搜索栏,我试图拦截POST,添加“ tag:”,然后提交,因此,如果有人在搜索栏中键入“ apple”,它就会出来tag:apple

<form method="get" action="/search" id="search-home">
            <button type="submit" value="search"></button>
            <input type="hidden" name="type" value="product" />
            <input type="text" name="q" placeholder="Search" />
        </form>
        <!doctype html>
        <html lang="en">
        <head>
        <meta charset="UTF-8">
        <meta name="Generator" content="EditPlus®">
        <meta name="Author" content="">
        <meta name="Keywords" content="">
        <meta name="Description" content="">
        <title>Document</title>
        <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
        <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
        </head>
        <body>

            <form method="get" action="/search" id="search-home">
                <button type="submit" value="search">submit</button>
                <input type="hidden" name="type" value="product" />
                <input type="text" name="q" placeholder="Search" class="searchtext"/>
            </form>

        <script>
        $(document).on('submit','#search-home',function(){
        var searchtext = $('.searchtext').val();
        $('.searchtext').val("tag:"+searchtext);
        });
        </script>

        </body>
        </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM