javascript 에서 웹 페이지 DOM 사용자 정의 속성 값 을 가 져 오고 사용자 정의 속성 값 을 설정 하 는 일반적인 방법

1649 단어 JavaScript
HTML  ,         。  ,      ,        ,                   。
Html , , , :
<input type=”button” value=”Click Me, Baby!” />
, , 2 , 。

, , , ; button :
<input type=”button” value=”Click Me, Baby!” clickCount=”0” />
, button clickCount, 0; js :
1. button click
<input type=”button” value=”Click Me, Baby!” clickCount=”0” onclick=”customAttributeDemo(this);" />
2. customAttributeDemo(obj)

IE , , IE DOM , ,IE :
function customAttributeDemo(obj)
{
if (obj.clickCount === '0')
{
obj.clickCount = '1';
}
else
{
obj.disabled = true;
}
}
FireFox , FireFox , , attributes[] ,FireFox :
function customAttributeDemo(obj)
{
if (obj.attributes['clickCount'].nodeValue === '0')
{
obj.attributes['clickCount'].nodeValue = '1';
}
else
{
obj.disabled = true;
}
}
, IE, , , ,

, getAttribute setAttribute :
function customAttributeDemo(obj)
{
if (obj.getAttribute('clickCount') === '0')
obj.setAttribute('clickCount', '1');
else
obj.disabled = true;
}

좋은 웹페이지 즐겨찾기