ホームページ  >  記事  >  ウェブフロントエンド  >  【html】ボタンに関する問題 button_html/css_WEB-ITnose

【html】ボタンに関する問題 button_html/css_WEB-ITnose

WBOY
WBOYオリジナル
2016-06-24 11:41:351111ブラウズ

問題: type 属性が設定されていない場合、ブラウザごとにボタンの動作が異なります。例:

html:

<!doctype html><html lang="en"><head>    <meta charset="UTF-8"/>    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>    <meta name="renderer" content="webkit"/>    <meta name="keywords" content=""/>    <meta name="description" content=""/>    <title>button按钮的一些问题</title></head><body>    <form action="result.php" method="post">        <input type="text" name="txt" placeholder="随便输入点什么吧!" autocomplete="off"/>        <button>button点击提交</button>    </form></body></html>

result.php:

<?php echo $_POST['txt'] ?>

ie8 以降ではボタンをクリックすると正常にフォームを送信できることがわかりましたが、ie6 と ie7 ではボタンをクリックしても応答がありません。ボタン。

理由:

なぜ違いがあるのですか?ボタン button には type 属性が設定されていないため、ブラウザごとに解析されるボタンの type タイプは異なります。

w3school を通じて、button ボタンには常に type 属性を指定する必要があることがわかります。 Internet Explorer (ie6 および ie7 でテスト済み) のデフォルトのタイプは「ボタン」です​​が、他のブラウザー (W3C 仕様を含む) のデフォルトは「送信」です。詳細については、ここをクリックしてください。

最後にデモを修正しました:

<!doctype html><html lang="en"><head>    <meta charset="UTF-8"/>    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>    <meta name="renderer" content="webkit"/>    <meta name="keywords" content=""/>    <meta name="description" content=""/>    <title>button按钮的一些问题</title></head><body>    <form action="result.php" method="post">        <input type="text" name="txt" placeholder="随便输入点什么吧!" autocomplete="off"/>        <button type="button">button按钮type为button</button>        <button type="submit">button按钮type为submit</button>    </form></body></html>

PS:

この記事を書く目的は、ボタンを使用するときに、ラベルに対応するタイプを指定する必要があることを思い出させることです。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。