【问题标题】:pass inputbox value as a querystring to URL将输入框值作为查询字符串传递给 URL
【发布时间】:2011-12-05 15:16:39
【问题描述】:

我有一个输入框和一个SEARCH 的链接,其样式看起来像一个搜索按钮。当用户在输入框中输入关键字时,我想抓取该关键字,将其传递,并将其作为搜索查询字符串附加到搜索 URL

/search/pages/physicians.aspx?v=relevance&s=Physicians&k=

所以如果Cardiologist 是关键字,它会是:

http://ABChospital.org/search/pages/physicians.aspx?v=relevance&s=Physicians&k=Cardiologist

如何在 jquery 中实现这一点?

<input name="KeywordBox" class="BasicSearchInputBox" type="text" value="Enter Keywords.."/>
            <div class="searchBtnHolder"> 
             <a class="searchButton" href="/search/pages/physicians.aspx?v=relevance&s=Physicians&k=" type="submit"><span>
             Search</span></a>

【问题讨论】:

  • 为什么不直接使用&lt;form&gt;&lt;input type="submit"&gt; 按钮?这个琐碎的 HTML 任务真的需要 jQuery 吗?

标签: jquery url query-string inputbox


【解决方案1】:

试试这个:

$('.searchButton').click(function() {
    location.href = this.href + $('.BasicSearchInputBox').val();
    return false;
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多