在 aspx 页面上实施 Google 自定义搜索的最佳方式

发布于 2024-07-04 03:34:44 字数 111 浏览 7 评论 0原文

Google 自定义搜索代码作为表单标签提供。 但是,Asp.net 只允许页面上有单个表单标记。 实现其代码的最佳方法是什么,以便您可以将其包含在 aspx 页面上(例如作为母版页或导航元素的一部分)。

Google custom search code is provided as a form tag. However, Asp.net only allows a single form tag on a page. What is the best way to implement their code so you can include it on an aspx page (say as part of a Masterpage or navigation element).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北笙凉宸 2024-07-11 03:34:44

一个 ASP.NET 页面上可以有多个表单标记。 限制在于服务器端 (runat="server") 表单标记。

您可以实现两个(或多个)表单标记,只要其中一个具有 runat="server" 属性并且一个不包含在另一个中即可。 例子:

<body>
<form action="http://www.google.com/cse" id="cse-search-box"> ... </form>
<form runat="server" id="aspNetform"> ... </form>
<body>

You can have multiple form tags on an ASP.NET page. The limitation is on server-side (runat="server") form tags.

You can implement two form tags (or more) as long as only one has the runat="server" attribute and one is not contained in the other. Example:

<body>
<form action="http://www.google.com/cse" id="cse-search-box"> ... </form>
<form runat="server" id="aspNetform"> ... </form>
<body>
标点 2024-07-11 03:34:44

您可以拥有多个表单标签,但请注意它们不能嵌套。 在这种情况下,您会遇到各种奇怪的情况(例如,我见过嵌套表单的开始标记显然被忽略,然后其结束标记最终关闭“父”表单的情况)。

You may be able to have multiple form tags, but note that they cannot be nested. You'll run into all kinds of weirdness in that scenario (e.g., I've seen cases where the opening tag for the nested form apparently gets ignored and then its closing tag winds up closing the "parent" form out).

世界和平 2024-07-11 03:34:44

您需要删除表单标签并使用 javascript 发送查询。 看一下
http://my6solutions.com/post/2009/04/19/Fishing-Google-Custom-Search-nested-form-tags-in-asp-net-pages.aspx

我已经包含了之前以及代码之后。 所以您可以看到我为将其与 blogengine .net 集成所做的工作。

You'll need to remove the form tag and use javascript send the query. Have a look at
http://my6solutions.com/post/2009/04/19/Fixing-Google-Custom-Search-nested-form-tags-in-asp-net-pages.aspx

I have included the before and after code as well. So you can see what I've done to integrate it with blogengine .net.

留一抹残留的笑 2024-07-11 03:34:44

你可以使用 JavaScript:

<input name="Query" type="text" class="searchField" id="Query" value="Search" size="15" onfocus="if(this.value == 'Search') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Search'; }" onkeydown="var event = event || window.event; var key = event.which || event.keyCode; if(key==13) window.open('http://www.google.com/search?q=' + getElementById('Query').value ); " /><input name="" type="button" class="searchButton" value="go" onclick="window.open('http://www.google.com/search?q=' + getElementById('Query').value );" />

You could use Javascript:

<input name="Query" type="text" class="searchField" id="Query" value="Search" size="15" onfocus="if(this.value == 'Search') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Search'; }" onkeydown="var event = event || window.event; var key = event.which || event.keyCode; if(key==13) window.open('http://www.google.com/search?q=' + getElementById('Query').value ); " /><input name="" type="button" class="searchButton" value="go" onclick="window.open('http://www.google.com/search?q=' + getElementById('Query').value );" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文