[javascript]要素の属性の取得方法

以下のようにボタンに「data-test」という要素の属性があり、クリックイベント時にjs側で属性を取得するサンプルです。

html側

<input type="button" onClick="registButton(this)" data-test="aaaaa">

javascript側

function registButton(obj) {
var val = obj.getAttribute("data-test");
alert(val);
}

Bookmark this on Yahoo Bookmark
Bookmark this on Google Bookmarks
Share on LinkedIn
LINEで送る
Pocket

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>