图片调用的js文件怎么写

JavaScript025

图片调用的js文件怎么写,第1张

将需要在js中修改的代码放在js变量中,该变量在js中定义,然后在insertHtml中添加这段代码,示例如下:

var code = "<a herf = '#'><img url = '#'></img></a>"

insertHtml("beforeend",document.body,code)

将包含上述代码的js引入到页面中即可,在页面上调用js的代码如下:

<script language=javascript src="test.js"></script>

insertHtml的使用方法:

insertHtml(where,el,html)

where:插入位置。包括beforeBegin,beforeEnd,afterBegin,afterEnd

el:用于参照插入位置的html元素对象

html;要插入的html代码

例:insertHtml("beforeEnd",document.getElementById("fav_list"),"<li id='aaa'><a href='www.baidu.com' class='fav_link'>百度</a></li>")

先设置一段JS代码,如:function DrawImage(MyPic,W,H){

var flag=false

var image=new Image()

image.src=MyPic.src

if(image.width>0 &&image.height>0){

flag=true

if(image.width/image.height>= W/H){

if(image.width>W){

MyPic.width=W

MyPic.height=(image.height*W)/image.width

}

else{

MyPic.width=image.width

MyPic.height=image.height

}

}

else{

if(image.height>H){

MyPic.height=H

MyPic.width=(image.width*H)/image.height

}

else{

MyPic.width=image.width

MyPic.height=image.height

}

}

}

}

图片读取:<img src="图片路径" onload=""javascript:DrawImage(this,200,120)""border=""0"" width=""200"" height=""120""/>

经常换网址是怎么个路数,

但通常来说下载地址都是相对网站根目录的(/A/B/C.rar),怎么跟网址扯上关系的

----------------------------------------------

一种可行的解决方案:

所有下载地址这么写:

<a href="javascript:down(这里是要下载的东西的ID)">下你没</a> <script>//通用js

    function down(id){

        var httpss="http:网址"

        window.location.href=httpss+"down.php?id="+id

        //这里也可以直接ajax down.php 获取下载地址(....zip这种)来进行直接下载--需要后端配合

    }

</script>

或者

<a href="javascript:down('/upload/2015/07/1314.zip')">下你没</a>

    <script>

        function down(src){

            var httpss="http://网址"

            window.location.href=httpss+src

        }

    </script>