JS操作属性
1.設定、取得、削除
setAttribute()のgetAttribute()removeAttribute()
<BODY> の<input type = "text"のクラス= "入力"値= "テスト"のデータ値= "1111"> <ボタンクラス= "BTN"> BTN1 </ボタン> <ボタンクラス= "BTN"> BTN2 </ボタン> <ボタンクラス= "BTN"> btn3 </ボタン> </ body> <スクリプト> VARの DOM = document.getElementsByClassName( '入力')[0 ]; VaRの btns = document.getElementsByClassName( 'BTN' ); // は、hasAttribute()判断对象是否有某属性、返回一个ブール值。 はconsole.log(dom.hasAttribute( 'データ値')); // 真 にconsole.log(dom.hasAttribute( 'プレースホルダ')); // プロパティ値を取得 するvarテキスト= dom.getAttribute( '値'の); VARのクラス名= dom.getAttribute( 'クラスの); VARの ID = dom.getAttribute( 'ID'); //は何のプロパティはnullを返しません取得 / / 設定/属性変更 dom.setAttribute( '値'、クラス名+テキスト+ ; ID)を dom.setAttribute( '無効' '無効' ;) この .setAttribute( '無効' '無効' ); } [btns。1] = .onclick 関数(){ // 属性削除 dom.removeAttribute( 'ディセーブル' )。 btns [0] .removeAttribute( '無効' )。 } </ SCRIPT>