【问题标题】:how to write the javascript code to get the effect?如何编写javascript代码来获得效果?
【发布时间】:2011-02-24 06:11:56
【问题描述】:

mysite 有两种搜索,一种是全站搜索。另一个是谷歌搜索。

html结构是:

<div class="fr_search">        
      <select class="search_l">
        <option value="0">the whole site search</option>
         <option value="1">google search</option>
      </select>

    <form action="1.php"  method="post" id="search-theme-form">      
   <input type="text" maxlength="128" name="search_theme_form" id="edit-search-theme-form-1" size="15" value="" title="input search term" class="form-text" />
   <input type="image" name="submit" id="edit-submit"  class="form-submit"     src/images/search_btn_top.gif" />
  <input type="hidden" name="form_build_id" id="form-9fb5cf2703f7df33fe84873222db2cbe" value="form-9fb5cf2703f7df33fe84873222db2cbe"  />
   <input type="hidden" name="form_id" id="edit-search-theme-form"   value="search_theme_form"  />  
</form>

现在,我想做的是当站点访问者从下拉列表中选择“整个站点搜索”时。当他在文本框中输入术语并单击提交按钮时,他会从站点中获得搜索结果。

当访问者从下拉列表中选择“google search”时。当他在文本框中输入搜索词并单击提交按钮时,他得到的搜索结果来自 Google 自定义搜索。 谢谢。

【问题讨论】:

  • 这会被选中吗?还是在他提交表格之后?
  • 不确定 - 我假设单击提交图像后,因为它存在。

标签: javascript jquery


【解决方案1】:

试试这样的:

$("#edit-submit").click(function() {
    if ($(".search_l")[0].val() == "0") {
        // site search
        $("#search-theme-form").submit();
    } else {
        // google
        window.location = "http://www.google.com/search?q=" + $("#edit-search-theme-form-1").attr("value");
    }
});

【讨论】:

  • 刚刚注意到您指定了 Google 自定义搜索 - 不确定 URL 将如何构建(或者是否实际上仍需要发布到页面)。
猜你喜欢
  • 1970-01-01
  • 2013-08-23
  • 2011-04-04
  • 2016-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-22
相关资源
最近更新 更多