【问题标题】:HTML post specific value on submit提交时的 HTML 帖子特定值
【发布时间】:2015-11-14 05:49:58
【问题描述】:

我有一个搜索栏,我试图拦截 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>

【问题讨论】:

  • 您可以在您将使用apple的地方进行操作
  • 你可以试试jQuery吗?
  • 你会用这个值做什么?
  • 我很困惑。我从这里stackoverflow.com/questions/11450307/… 尝试了答案,但无法正常工作。

标签: javascript jquery html search


【解决方案1】:
        <!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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 2014-04-03
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    相关资源
    最近更新 更多