index.html网页文件======
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title></head><body><img src="style/teng/digg.gif" width="800" height="52" name="a"/>
</body>
</html>
然后我想写一个外部js文件,功能是获取<img>中scr属性中的"style/teng/"字符串,.我想要把js文件和网页文件分离开来,怎么写,请助~~~~~~谢谢....

解决方案 »

  1.   


    //a.js 在HTML页面引入a.js
    window.onload = function(){
    alert(document.getElementsByName("a")[0].src)//取完做下处理
    }
      

  2.   

    楼上的用法好厉害,但是有这个getElementByName函数么
    还是老实点吧window.onload=function() //当页面完全加载后执行
    {
     var _img = document.getElementByTagName("img")[0];
     var _style = _img.getAttribute("style");
    }
      

  3.   

    //楼主不知者不怪,但你可以查下百度啊...还有是document.getElementsByName你那还少个s