2017-01-10 35 views
0

のonclickイベントを経由して表示されていない属性:入力は、私はこのようなヒスイ/パグビューでシンプルなラジオボタン形式持っ

function radioClick(e){ 
    console.log(e) 
    console.log(e.my_prop) 
    console.log(e.group) 
    console.log(e.type) 
    console.log(e.id) 
} 
:私のJSスクリプトで

form 
    input(type='radio',id="0", group="group0", value="some string" my_prop="hello", onclick='radioClick(this)') 

を、私はこのようなradioClick機能を定義しています

出力は次のようになります。

<input type="radio" my_prop="hello" group="0" id="0" value="some string" onclick="radioClick(this)"> 
undefined //<--- Why are these undefined? 
undefined //<--- Why are these undefined? 
radio 
0 

なぜ属性groupとがありますmy_propは未定義ですか?イベントonclickがトリガーされたときに、どのようにアクセスできますか?

答えて

1

getAttribute()を使用して、文字列に目的の属性を配置できます。

function radioClick(e){ 
 
    console.log(e.getAttribute('my_prop')); 
 
    console.log(e.getAttribute('group')); 
 
    console.log(e.getAttribute('type')); 
 
    console.log(e.getAttribute('id')); 
 
}
<input type="radio" my_prop="hello" group="0" id="0" value="some string" onclick="radioClick(this)">
作品

+0

!なぜアクセス可能な属性とそうでない属性がありますか? –

関連する問題