<html>
<head>
<title>study</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<script type="text/javascript" language="javascript">
<!--
function serchDOM(){
var oimg=document.getElementsByTagName("img")[0]; //得到第一个图像对象
alert(oimg.getAttribute("alt")); //pobaby
}
-->
</script>
</head>
<body onload="serchDOM()">
<img alt="pobaby" src="1.jpg" />
</body>
</html>
<head>
<title>study</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<script type="text/javascript" language="javascript">
<!--
function serchDOM(){
var oimg=document.getElementsByTagName("img")[0]; //得到第一个图像对象
alert(oimg.getAttribute("alt")); //pobaby
}
-->
</script>
</head>
<body onload="serchDOM()">
<img alt="pobaby" src="1.jpg" />
</body>
</html>
本文提供了一个使用JavaScript操作网页中图像元素的例子,通过获取页面上的第一个图像对象并读取其alt属性值来展示基本的DOM操作技巧。
2145

被折叠的 条评论
为什么被折叠?



