首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

怎么在html调用js函数将参数传递给js函数中

2012-03-26 
如何在html调用js函数将参数传递给js函数中?script typetext/javascriptfunction RefreshHint() {var

如何在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 ?

[解决办法]

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去遍历他的子节点,

然后,判断那个子节点上有鼠标事件

热点排行