2013年8月30日金曜日

HtmlのButtonタグをSubmitさせない方法

特に何も指定しないとFormのタグの中にbuttonはinput type="submit"と同様な動きになってしまう。
例)

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Hoge</title>
  </head>
  <body>
    <form method="POST" action="/hoge">
      <p>
 ほげ:<input type="text" name="hogename">
      </p>
      <p>
 <button >送信する</button>
      </p>
    </form>
  </body>
</html>
そこで、buttonタグをただのbuttonとして認識させるには、以下のようにbuttonタグに追加する必要がある。



<button type="button"></button>

上記の例にすると以下のようになる。
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>Hoge</title>
  </head>
  <body>
    <form method="POST" action="/hoge">
      <p>
 ほげ:<input type="text" name="hogename">
      </p>
      <p>
 <button type="button">送信する</button>
      </p>
    </form>
  </body>
</html>

単純だけど忘れがちになるのでメモとして記載しておきました。

Written By : // 12:22
Category:

0 コメント:

コメントを投稿

 

About

このブログは筆者の備忘録として色々記載しています。
Powered by Blogger.