Document.forms - form要素
formsは、Documentのプロパティです。ドキュメントの全てのform要素を返します。
概要
- 名前
- forms
- 所属
- Document
- IDL
[SameObject] readonly attribute HTMLCollection forms;
- 仕様書
- https://html.spec.whatwg.org/multipage/dom.html#dom-document-forms
説明
全てのform要素をHTMLCollectionで返す。読み取り専用なので、値を代入して変更することはできない。
チュートリアル
Document.formsを利用して、form要素を取得する例です。
<form action="https://syncer.jp/"></form>
<form action="https://example.com/"></form>
var forms = document.forms ;
forms[0] ; // <form action="https://syncer.jp/">
forms[1] ; // <form action="https://example.com/">
Document.getElementsByTagName()と同じです。
var forms = document.forms ;
var forms = document.getElementsByTagName( "form" ) ;
デモ
Document.formsのデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<head>
<base target="_blank">
</head>
<body>
<form action="https://syncer.jp/">
<input name="hoge" value="fuga">
<button>送信</button>
</form>
<form action="https://example.com/">
<input name="piyo" value="toto">
<button>送信</button>
</form>
<hr>
<script>
var value = document.forms ;
console.log( value ) ;
document.body.appendChild( new Text( value ) ) ;
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● | ● | ● | ● | ● | ● | ● | ● |
関連記事
- Document.images
- imagesは、Documentのプロパティです。ドキュメントの全てのimg要素を返します。
- Document.getElementsByClassName()
- getElementsByClassName()は、Documentのメソッドです。class属性を指定して要素を取得します。
- ラジオボタンの値を取得する
- どのラジオボタンが選択状態かを取得するには、要素のcheckedプロパティを確認します。
- Document()
- Document()は、Documentのコンストラクタです。新しいオブジェクトを作成します。