「html」document.formsのサンプル

構文
collection = document.forms;
文書のすべてのフォームを列挙する HTMLCollection オブジェクトです。コレクションのそれぞれの項目は、
単一の <form> 要素を表す HTMLFormElement です。
使用例
1.フォーム情報の取得

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html lang="en">
<head>
<title>document.formsサンプル/title>
</head>
<body>
<form id="frmA">
<input type="button" onclick="alert(document.forms[0].id);" value="frmA's form" />
</form>
<form id="frmB">
<input type="button" onclick="alert(document.forms[1].id);" value="frmB's form" />
</form>
<form id="frmC">
<input type="button" onclick="alert(document.forms[2].id);" value="frmC's form" />
</form>
</body>
</html>
<!DOCTYPE html> <html lang="en"> <head> <title>document.formsサンプル/title> </head> <body> <form id="frmA"> <input type="button" onclick="alert(document.forms[0].id);" value="frmA's form" /> </form> <form id="frmB"> <input type="button" onclick="alert(document.forms[1].id);" value="frmB's form" /> </form> <form id="frmC"> <input type="button" onclick="alert(document.forms[2].id);" value="frmC's form" /> </form> </body> </html>
<!DOCTYPE html>
<html lang="en">

<head>
<title>document.formsサンプル/title>
</head>

<body>

<form id="frmA">
  <input type="button" onclick="alert(document.forms[0].id);" value="frmA's form" />
</form>

<form id="frmB">
  <input type="button" onclick="alert(document.forms[1].id);" value="frmB's form" />
</form>

<form id="frmC">
  <input type="button" onclick="alert(document.forms[2].id);" value="frmC's form" />
</form>

</body>
</html>

2.フォーム内要素の取得

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
var selectForm = document.forms[0];
var selectFormElement = document.forms[0].elements[0];
var selectForm = document.forms[0]; var selectFormElement = document.forms[0].elements[0];
var selectForm = document.forms[0];
var selectFormElement = document.forms[0].elements[0];

 

Html

Posted by arkgame