HTML: submit と button の違い
HTML の input タグの type="submit" と type="button" の違いを見てみましょう。【sample1.html】
<html><body>
<form method="get" action="page2.html">
<input type="submit" value="submit1" onclick="location.href='page1.html'" />
<input type="submit" value="submit2" />
<input type="button" value="button1" onclick="location.href='page1.html'" />
<input type="button" value="button2" />
</form>
</body></html>
【sample2.html】
<html><body>
<form method="get">
<input type="submit" value="submit3" onclick="location.href='page1.html'" />
<input type="submit" value="submit4" />
</form>
</body></html>
【page1.html】
<html><body>page1</body></html>
【page2.html】
<html><body>page2</body></html>
【結果】
・sample1.html の submit1 押下: page2.html に画面遷移します。
・sample1.html の submit2 押下: page2.html に画面遷移します。
・sample1.html の button1 押下: page1.html に画面遷移します。
・sample1.html の button2 押下: 画面遷移しません。
・sample2.html の submit3 押下: 画面遷移しません。
・sample2.html の submit4 押下: 画面遷移しません。