<html>
<head>
<title>Attribute Test</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<font id="test" size="2" color="red">Change my attributes!</font>
<script type="text/javascript">
<!--
theElement = document.getElementById('test');
theElement.setAttribute('color','blue');
theElement.setAttribute('undefinedAttribute','blue');
theElement.color='red';
document.all.test.color = 'blue';
//-->
</script>
<form name="testform" id="testform" action="#" method="get">
Color: <input type="text" id="color" name="color" value="" size="8" />
<input type="button" value="Set Color"
οnclick="theElement.setAttribute('color',document.testform.color.value);" />
<input type="button" value="Remove Color"
οnclick="theElement.removeAttribute('color');" />
<br />
Size:
<select οnchange="theElement.setAttribute('size',this.options[this.selectedIndex].text);">
<option>1</option>
<option>2</option>
<option selected="selected">3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
</form>
<script>
<!--
document.forms[0].test.color = 'red';
document.testform.test.color = 'blue';
-->
</script>
<script type="text/javascript">
<!--
document.testform.color.value = theElement.getAttribute('color');
//-->
</script>
</body>
</html>
dom对属性操作实例
最新推荐文章于 2023-01-10 15:00:02 发布