3

検索フォームの送信ボタンとして画像を使用しています。つまり、次のようになります。

<input id="search" type="image" alt="Search" src="/images/searchButton.png" name=""/>

これは、ChromeとFirefoxで不幸な副作用があります。たとえば、「食品」を検索すると、次のページに移動します。パラメータ&x = 0&y=0が検索結果のURLの最後に表示されます。

main/search?search=food&x=0&y=0

オンラインでの検索では、画像を使用してフォームを送信する場合、これが標準的な動作であることが示されています。

Digg.comは画像を使用して検索フォームを送信しますが、この動作を回避していることに気付きました。彼らがどうやってそれをしているのか理解できません。フォームの送信にJavascriptを使用していないようです。誰か教えてもらえますか?

4

4 に答える 4

4

Digg is using JavaScript to do that. Try submitting the search form with JavaScript disabled in your browser.

于 2009-12-28T22:16:18.903 に答える
2

Instead of using an <input type="image">, you could use a <button> element:

<button type="submit" style="border: 0; background: transparent">
  <img src="image.png"></img>
</button>
于 2009-12-28T22:29:30.430 に答える
1

Those parameters denote the location in which the click was exercised upon the image, which is the default behavior of most if not all browsers when it comes to using images as submit buttons. You can use a workaround that basically goes through JavaScript to submit your form, much like what you see in watain's example. Or you can create a submit button thats not a form element, by utilizing form.submit() as the action attached to that image.

于 2009-12-28T22:25:25.620 に答える
0

You could use Javascript to submit the form like that, it's still the easiest way:

<script>
yourForm.onSubmit = function() {
 location.href = 'main/search?search=' + encodeURIComponent(yourForm.elements['query'].value);
 return false;
}
</script>

Unfortunately I don't know how they do it without Javascript.

EDIT: Btw you could also use a simple which will submit the form when it gets clicked.

于 2009-12-28T22:11:11.673 に答える