9章フォーム[js]——javaScript宝典
1900 ワード
9.1 formオブジェクト
フォームオブジェクト
document.forms[0]
要素名の文字列を配列の下付き文字として使用します。
document.forms[formName]
注意:配列参照単語の複素形
フォーム名document.formNameも使用できます。
9.1アクセスフォームのプロパティ
document.forms[0].action="http://www.howia.net」「 //属性の直接割り当てを変更します。
document.formName.target
9.2オブジェクトとしてのフォームコントロール
例えば
9.2.3チェックボックスのオブジェクト
9.2.4ラジオ枠オブジェクト
グループのボタン数を読みだします。
document.forms[0].groupName.length
あるボタンが高いかどうか調べたいのですが、【check属性】が表示されます。
document.forms[0].group Name.hecked
9.2.5 Selectオブジェクト
selectの最も重要な属性selectedIndex
selectedIndex属性は、ドロップダウンリストで選択されたオプションの索引番号を設定または戻すことができます。
document.forms[0].selectName.selectedIndex
その中の2つの重要な属性textとvalue
doucument.forms[0].selectName.options[n].text
doucument.forms[0].selectName.options[n].value
例
(1)onchange=「uperMe(this)」
受信側では、関数がパラメータ変数を定義して参照を変数に変換します。この変数は関数の他のステートメントで使用できます。
finction uperMe(filed){
statment[s]
)
(2)thisキーワードを使って、現在のコントロールを参照し、form属性を加えて、this.formのようにします。
onclick=「inspact(this.form)」
関数の定義にはformオブジェクト参照としてパラメータ変数が割り当てられています。変数名を決定することができます。または変数名を使用しないことができます。
function inspact(form){
statment[s]
)
9.4提出と事前認証フォーム
document.forms[0].submit()
フォームオブジェクト
document.forms[0]
要素名の文字列を配列の下付き文字として使用します。
document.forms[formName]
注意:配列参照単語の複素形
フォーム名document.formNameも使用できます。
9.1アクセスフォームのプロパティ
document.forms[0].action="http://www.howia.net」「 //属性の直接割り当てを変更します。
document.formName.target
9.2オブジェクトとしてのフォームコントロール
例えば
<form name="searchForm">
<input type="text" name="entry">
<input type="submit" name="sender" value="Serach">
</form>
テキストにコントロールを入力する以下のものが有効です。document.searchForm.entry
document.searchForm.elements[0]
document.forms["searchForm"].elements["entry"]
document.forms["searchForm"].entry
9.2.2ボタンオブジェクト9.2.3チェックボックスのオブジェクト
9.2.4ラジオ枠オブジェクト
グループのボタン数を読みだします。
document.forms[0].groupName.length
あるボタンが高いかどうか調べたいのですが、【check属性】が表示されます。
document.forms[0].group Name.hecked
9.2.5 Selectオブジェクト
selectの最も重要な属性selectedIndex
selectedIndex属性は、ドロップダウンリストで選択されたオプションの索引番号を設定または戻すことができます。
document.forms[0].selectName.selectedIndex
その中の2つの重要な属性textとvalue
doucument.forms[0].selectName.options[n].text
doucument.forms[0].selectName.options[n].value
例
function goThere()
{
var list=document.forms[0].urlList;
location.href=list.options[list.selectedIndex].value;
}
9.3フォームデータと要素を関数に伝える(1)onchange=「uperMe(this)」
受信側では、関数がパラメータ変数を定義して参照を変数に変換します。この変数は関数の他のステートメントで使用できます。
finction uperMe(filed){
statment[s]
)
(2)thisキーワードを使って、現在のコントロールを参照し、form属性を加えて、this.formのようにします。
onclick=「inspact(this.form)」
関数の定義にはformオブジェクト参照としてパラメータ変数が割り当てられています。変数名を決定することができます。または変数名を使用しないことができます。
function inspact(form){
statment[s]
)
9.4提出と事前認証フォーム
document.forms[0].submit()