getElementsByName这个是document的方法
try
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<div>
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go();">
<div name="go">aa</div>
</div>
</div>
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
function go(){
alert(document.getElementsByName("go")[0].innerHTML);
}
</SCRIPT>
try
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<div>
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go();">
<div name="go">aa</div>
</div>
</div>
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
function go(){
alert(document.getElementsByName("go")[0].innerHTML);
}
</SCRIPT>
2 collObjects = document.getElementsByName(sNameValue),而非任意元素都可用此方法!改了改
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="[email protected]" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<div>
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go(this);">
<div id="go">aa</div>
</div>
</div>
</body>
<script type="text/javascript">
<!--
function go(which)
{
alert(document.getElementById("go").innerHTML);
// 其实 which 没用!
alert(which.style.width);
}
//-->
</script>
</html>
送你三本手册!DHTML参考手册
http://download.csdn.net/source/308913样式表中文手册
http://download.csdn.net/source/304124JScript语言参考
http://download.csdn.net/source/308916
如果我用了很多层
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go(this);">
<div name="go"> aa </div>
</div>
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go(this);">
<div name="go">bb </div>
</div>
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go(this);">
<div name="go"> cc </div>
</div>
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go(this);">
<div name="go"> dd </div>
</div> 这样难道就没办法只通过this传输对象来实现么..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="[email protected]" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go(this);">
<div id="go"> aa </div>
</div>
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go(this);">
<div id="go"> bb </div>
</div>
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go(this);">
<div id="go"> cc </div>
</div>
<div style="border:1px solid #ccc;width:300px;height:300px;" onclick="go(this);">
<div id="go"> dd </div>
</div>
</body>
<script type="text/javascript">
<!--
function go(which)
{
var cDiv = which.getElementsByTagName("div");
for (var i=0; i<cDiv.length; i++)
{
if (cDiv[i].id = "go")
{
alert(cDiv[i].innerHTML);
break;
}
}
}
//-->
</script>
</html>
function go(which)
{
var cDiv = which.getElementsByTagName("div");
for (var i=0; i<cDiv.length; i++)
{
if (cDiv[i].id == "go")
{
alert(cDiv[i].innerHTML);
break;
}
}
}