TOP - JavaScript - Document - forms[]配列

フォーム内のHTML要素のオブジェクトが格納される配列です。


オブジェクト1.forms[]

オブジェクト1 : Documentオブジェクト(通常は、window.document等)


(例)

<SCRIPT type="text/javascript">
    var w1;

    function btnclick()
    {
        w1 = window.open("", "", "height=150,width=300");
        w1.moveTo(200,300);
        var s_html = "";
        s_html += "<html>\n";
        s_html += "<head>\n";
        s_html += '<script type="text/javascript">' + "\n";
        s_html += "<!--\n";
        s_html += 'function view_form()' + "\n";
        s_html += '{' + "\n";
        s_html += '    var i = 0;' + "\n";
        s_html += '    var s_form = "";' + "\n";
        s_html += '    for (i=0; i<window.document.forms.length; i++)' + "\n";
        s_html += '    {' + "\n";
        s_html += '        s_form += window.document.forms[i].name + "\\n";' + "\n";
        s_html += '    }' + "\n";
        s_html += '    alert(s_form);' + "\n";
        s_html += '}' + "\n";
        s_html += "\/\/-->\n";
        s_html += "<\/script>\n";
        s_html += "</head>\n";
        s_html += "<body>\n";
        s_html += '<form name="form1">' + "\n";
        s_html += '<input type="button" name="view_button" value="FORM内のオブジェクト" ';
        s_html += 'onclick="view_form()"><br>' + "\n";
        s_html += '</form>' + "\n";
        s_html += '<form name="form2">' + "\n";
        s_html += '<input type="text" name="form_text" value="form2">' + "\n";
        s_html += '</form>' + "\n";
        s_html += "</body>\n";
        s_html += "</html>\n";
        w1.document.write(s_html);
        w1.document.close();
    }
<!--
//-->
</SCRIPT>


Copyright(C) 2006-2011 CLAYPOT. All Rights Reserved.