inputタグのtypeにtextとかhiddenを複数指定したらどっちが優先されるの?
はじめに
input
タグのtype
属性に複数の値を指定したらどうなるか気になったので検証してみた。
ソースコード
index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
</head>
<body>
<form method="post" action='sample.php'>
<input type='text' name='sample1' value="text"><br>
<input type='hidden' name='sample2' value="hidden"><br>
<input type='password' name='sample3' value="password"><br>
<input type='url' name='sample4' value="http://url.url"><br>
<!-- ここからミックス -->
<input type='text hidden' name='sample5' value="text hidden"><br>
<input type='hidden text' name='sample6' value="hidden text"><br>
<input type='text password' name='sample7' value="text passowrd"><br>
<input type='password text' name='sample8' value="password text"><br>
<input type='text url' name='sample9' value="text url"><br>
<input type='url text' name='sample10' value="url text"><br>
<input type='hidden hidden' name='sample11' value="hidden hidden"><br>
<input type='text hidden passowrd url' name='sample12' value="text hidden password url"><br>
<button type='submit'>送信</button><br>
</form>
</body>
</html>
sample.php
<?php
echo('<pre>');
var_dump($_POST);
echo('</pre>');
結果
画面
ポスト値
考察
-
text hidden
が画面に表示されているのでhidden
は効いていない - 先頭に指定されているものが反映されるのか?と思い
hidden text
にするもhidden
は効かず -
password
の方も同様でpassword
属性が効いていない(入力欄のものが●●●のような伏せ字になっていない) - 上記の状態で送信が行えるので
url
属性も効いていない
結論
type
に複数の属性は指定できない
考えて見れば当たり前のことでtype='hidden'
は用意されているがtype='hidden url'
は用意されていないので、無効な属性と判断されデフォルト値になる。
input
のtype
のデフォルト値はtext
なので組み合わせて指定したものは全てtext
としての挙動を示してることが分かる。
納得納得
参考
type属性一覧はこちらを参照した。
Author And Source
この問題について(inputタグのtypeにtextとかhiddenを複数指定したらどっちが優先されるの?), 我々は、より多くの情報をここで見つけました https://qiita.com/yamamoto_hiroya/items/ffe95439c42f02e490da著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .