0

サイト検索をグーグルカスタム検索に移動しています。

テキストの古い入力は次のようになります。

<input type="text" value="Search this website..." name="s" id="searchbox" onfocus="if (this.value == 'Search this website...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search this website...';}" />

次に、attr'name'を'q'として持つ必要があります。

<input type="text" value="Search this website..." name="q" id="searchbox" onfocus="if (this.value == 'Search this website...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search this website...';}" />

奇妙なことに、名前をqに切り替えると、フォーカスのある検索ボックスをクリアできなくなります。私はとても簡単なものが欠けていますか?

4

2 に答える 2

1

CSE JSも含めていますか?フォーカスとブラーハンドラーを上書きしている可能性があります。デフォルトの実装(ページの上部を参照)は、Googleブランドの透かしを追加します。

JSなしでCSEを実装できます。その場合、コードは正常に機能します。

<form action="http://www.google.com/cse" id="cse-search-box">
    <input name="cx" type="hidden" value="yoursearchid" />
    <input name="ie" type="hidden" value="UTF-8" />
    <input name="q" type="text" value="Search this website..." onfocus="if (this.value == 'Search this website...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search this website...';}" />
    <input name="sa" type="submit" value="Search" />
</form>
于 2010-05-20T18:53:38.130 に答える
-1

なぜそうなるのかはわかりませんが、JavaScriptを使用せずに、次のplaceholder属性を使用してHTMLに処理を任せることをお勧めします。

<input type="text" placeholder="Search this website..." name="q" id="searchbox" />
于 2010-05-20T18:05:54.897 に答える