formオブジェクトButtonオブジェクト
- Buttonオブジェクト一覧
- アクセスキー〔accessKeyプロパティ〕
- ボタンの無効化の有無を取得・設定〔disabledプロパティ〕
- フォーム?〔Formプロパティ〕
- ボタン名を取得〔nameプロパティ〕
- ボタンのタイプを取得〔typeプロパティ〕
- ボタンの値を取得・設定〔valueプロパティ〕
- ボタンにフォーカスを当てる/ボタンからフォーカスを外す〔blur()、focus()メソッド〕
- ボタンを自動的にクリックする〔click()メソッド〕
Buttonオブジェクト一覧
unknown
アクセスキー
accessKeyプロパティ
unknown
ボタンオブジェクト.accesskey;
<form action="#" name="frmA">
<p>
<input type="reset" name="btn_reset" value="リセット(R)" accesskey="R" />
<input type="submit" name="btn_submit" value="送信(U)" accesskey="S" />
</p>
<script type="text/javascript">
document.write("リセットボタンのアクセスキー="+document.frmA.btn_reset.accessKey+"<br \/>");
document.write("送信ボタンのアクセスキー="+document.frmA.btn_submit.accessKey+"<br \/>");
</script>
</form>
ボタンの無効化の有無を取得・設定
disabledプロパティ
unknown
ボタンオブジェクト.disabled;
<form action="#" onsubmit="alert('サンプルのため送信しません'); return false;">
<p>チェックボックスの状態によってボタンを有効化・無効化</p>
<p>
<label for="agree"><input type="checkbox" value="1" name="agree" id="agree" onclick="this.form.btn_regist.disabled=!this.checked;">同意する</label><br>
<input type="button" name="btn_regist" value="登録" />
</p>
</form>
フォーム?
Formプロパティ
unknown
ボタンオブジェクト.form;
<form action="#" name="frmA">
<p>
<input type="button" name="btn_reset" value="リセット(R)" onclick="alert(this.form)" />
</p>
</form>
ボタン名を取得
nameプロパティ
unknown
ボタンオブジェクト.name;
<form action="#" onsubmit="alert('サンプルのため送信しません'); return false;">
<p>
<input type="button" name="btnN" value="ボタンの名前を取得" onclick="alert(this.name)" />
</p>
</form>
ボタンのタイプを取得
typeプロパティ
unknown
ボタンオブジェクト.type
<form action="#" onsubmit="alert('サンプルのため送信しません'); return false;">
<p>
<input type="button" value="ボタンTのタイプを取得" onclick="alert(this.form.btnT.type)" />
<input type="button" value="ボタンTのタイプをsubmitに設定" onclick="this.form.btnT.type='submit'" />
</p>
<p>
<input type="button" name="btnT" value="ボタンT" />
</p>
</form>
ボタンの値を取得・設定
valueプロパティ
unknown
ボタンオブジェクト.value;
<form action="#">
<p>
<input type="button" name="btnVa" value="★ボタン★" onclick="this.value=((this.value=='★ボタン★') ? '☆ボタン☆' : '★ボタン★');" />
</p>
</form>
ボタンにフォーカスを当てる/ボタンからフォーカスを外す
blur()、focus()メソッド
unknown
ボタンオブジェクト.blur();
ボタンオブジェクト.focus();
ボタンオブジェクト.focus();
<form action="#">
<p>
<input type="button" onclick="this.form.btnA.focus();" value="ボタンAにフォーカスを当てる" />
<input type="button" onclick="this.form.btnA.blur();" value="ボタンAからフォーカスを外す" />
<input type="button" onclick="this.form.btnB.focus();" value="ボタンBにフォーカスを当てる" />
<input type="button" onclick="this.form.btnA.blur();" value="ボタンBからフォーカスを外す" />
</p>
<p>
<input type="button" name="btnA" value="btnA" />
<input type="button" name="btnB" value="btnB" />
</p>
</form>
ボタンを自動的にクリックする
click()メソッド
unknown
ボタンオブジェクト.click();
<form action="#">
<p>
<input type="button" onclick="this.form.btnC.click();" value="ボタンCを自動クリック" />
<input type="button" onclick="this.form.btnD.click();" value="ボタンDを自動クリック" />
</p>
<p>
<input type="button" name="btnC" value="btnC" onclick="alert(this.value+'がクリックされました')" />
<input type="button" name="btnD" value="btnD" onclick="alert(this.value+'がクリックされました')" />
</p>
</form>