html调用图片函数,ASP取出HTML里面的图片地址的函数

Function getimgs(str)

getimgs=""

Set objRegExp1 = New Regexp

objRegExp1.IgnoreCase = True

objRegExp1.Global = True

objRegExp1.Pattern = "http://.+?"""'取出里面的地址

set mm=objRegExp1.Execute(str)

For Each Match1 in mm

getimgs=getimgs&left(Match1.Value,len(Match1.Value)-1)&"||"'把里面的地址串起来备用

next

End Function

'取得图片内容

function getHTTPPage(url)

on error resume next

dim http

set http=server.createobject("MSXML2.XMLHTTP")'使用xmlhttp的方法来获得图片的内容

Http.open "GET",url,false

Http.send()

if Http.readystate<>4 then

exit function

end if

getHTTPPage=Http.responseBody

set http=nothing

if err.number<>0 then err.Clear

end function

'保存图片

function saveimage(from,tofile)

dim geturl,objStream,imgs

geturl=trim(from)

imgs=gethttppage(geturl)'取得图片的具休内容的过程

Set objStream = Server.CreateObject("ADODB.Stream")'建立ADODB.Stream对象,必须要ADO 2.5以上版本

objStream.Type =1'以二进制模式打开

objStream.Open

objstream.write imgs'将字符串内容写入缓冲

objstream.SaveToFile server.mappath(tofile),2'-将缓冲的内容写入文件

objstream.Close()'关闭对象

set objstream=nothing

end function

'调用实例

Dim strpic,i,fname

strpic = ShowPic("

")

strpic = Split(strpic,"||")

If UBound(strpic) > 0 Then

For i = 0 To UBound(strpic) - 1

'保存图片

fname=cstr(i&mid(strpic(i),instrrev(strpic(i),".")))

saveimage(strpic(i),fname)

Next

Else

End If

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ASP.NET 中,可以使用 Code-behind 文件来编写 C# 代码,并在前端页面中调用这些代码中的函数。具体步骤如下: 1. 在 ASP.NET 项目中创建一个 Code-behind 文件,比如 Default.aspx.cs。 2. 在 Code-behind 文件中定义一个公共函数,比如: ``` public void MyFunction(string param) { // Do something with param } ``` 3. 在前端页面中添加一个按钮或者其他触发事件,比如: ``` <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" /> ``` 4. 在前端页面对应的 Code-behind 文件中,添加一个事件处理函数,并在其中调用之前定义的公共函数,比如: ``` protected void btnSubmit_Click(object sender, EventArgs e) { string myParam = "Hello"; MyFunction(myParam); } ``` 在 JavaScript 中调用 C# 函数则需要使用 Ajax 技术。具体步骤如下: 1. 在 C# 中创建一个 WebMethod,使用 [WebMethod] 标志进行标记,比如: ``` [WebMethod] public static string MyFunction(string param) { // Do something with param return "Result"; } ``` 2. 在 JavaScript 中使用 Ajax 发送一个 POST 请求到 C# 的 WebMethod,比如: ``` $.ajax({ type: "POST", url: "MyPage.aspx/MyFunction", data: JSON.stringify({ param: "Hello" }), contentType: "application/json; charset=utf-8", dataType: "json", success: function (result) { alert(result.d); } }); ``` 其中,MyPage.aspx 是包含 MyFunction 的 ASP.NET 页面的名称,result.d 是返回的结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值