怎么在html调用js函数将参数传递给js函数中
如何在html调用js函数将参数传递给js函数中?
<script type="text/javascript">
function RefreshHint() {
var img_src = document.getElementById('nav_content').getElementsByTagName('img');
for (i=0; i<img_src.length; i++)
alert(img_src.item(i).id);
}
</script>
<html>
<head>
</head>
<body>
<div class="nav_content_bottom" id="nav_content">
<div class="pic">
<img src="jpg/01.jpg" onmouseover="RefreshHint()" id="1" />
</div>
<div class="pic">
<img src="jpg/02.jpg" onmouseover="RefreshHint()" id="2" />
</div>
</div>
</body>
</html>
当鼠标每个img上移入的时候, 调用RefreshHint, 怎么让函数知道鼠标移入了哪个img ?
------解决方案--------------------
<script type="text/javascript">
function RefreshHint() {
var img_src = document.getElementById('nav_content').getElementsByTagName('img');
for (i=0; i<img_src.length; i++)
alert(img_src.item(i).id);
}
</script>
<html>
<head>
</head>
<body>
<div class="nav_content_bottom" id="nav_content">
<div class="pic">
<img src="jpg/01.jpg" onmouseover="RefreshHint()" id="1" />
</div>
<div class="pic">
<img src="jpg/02.jpg" onmouseover="RefreshHint()" id="2" />
</div>
</div>
</body>
</html>
当鼠标每个img上移入的时候, 调用RefreshHint, 怎么让函数知道鼠标移入了哪个img ?
------解决方案--------------------
- HTML code
<html> <head> <script type="text/javascript"> function RefreshHint(obj) { alert(obj.id); } </script> </head> <body> <div class="nav_content_bottom" id="nav_content"> <div class="pic"> <img src="jpg/01.jpg" onmouseover="RefreshHint(this)" id="1" /> </div> <div class="pic"> <img src="jpg/02.jpg" onmouseover="RefreshHint(this)" id="2" /> </div> </div> </body> </html>
------解决方案--------------------
通过ID去遍历他的子节点,
然后,判断那个子节点上有鼠标事件