在鼠标上执行经典ASP代码(Execute classic ASP code on mouse over)

编程入门 行业动态 更新时间:2024-10-25 08:27:11
鼠标上执行经典ASP代码(Execute classic ASP code on mouse over)

我想将鼠标悬停在div上时执行此经典ASP代码。

<% dim s s=Request.QueryString("undercity") Response.Write(s) set fs=Server.CreateObject("Scripting.FileSystemObject") if s<>"" then set f=fs.OpenTextFile(Server.MapPath("RDS/rds.txt"),2,true) f.WriteLine(s) f.Close Set f=Nothing else if (fs.FileExists(Server.MapPath("RDS/rds.txt")))=true then set f=fs.OpenTextFile(Server.MapPath("RDS/rds.txt"),1) Response.Write("On air: "+f.ReadAll) f.Close Set f=Nothing end if end if set fs=Nothing %>

我尝试使用.innerHTML="<% code %>"在我的js文件上创建一个函数,但它不起作用。

这应该怎么做?

I would like to execute this Classic ASP code when passing the mouse over a div.

<% dim s s=Request.QueryString("undercity") Response.Write(s) set fs=Server.CreateObject("Scripting.FileSystemObject") if s<>"" then set f=fs.OpenTextFile(Server.MapPath("RDS/rds.txt"),2,true) f.WriteLine(s) f.Close Set f=Nothing else if (fs.FileExists(Server.MapPath("RDS/rds.txt")))=true then set f=fs.OpenTextFile(Server.MapPath("RDS/rds.txt"),1) Response.Write("On air: "+f.ReadAll) f.Close Set f=Nothing end if end if set fs=Nothing %>

I tried creating a function on my js file using the .innerHTML="<% code %>" but it didn't work.

How should this be done?

最满意答案

你不能那样做那样。 关键是客户端计算机上发生“传递鼠标”事件。 ASP代码在服务器计算机上运行的位置。 所以你必须有一些方法将它们连接在一起。

他们似乎一起工作的方式是,当用户在他们的机器上使用浏览器请求asp页面时,他们的浏览器向您的Web服务器发送请求,您的Web服务器运行您的asp代码,该代码生成HTML代码。 然后它将结果HTML代码发送到客户端,客户端浏览器接收结果HTML代码,然后从那里接管。 在此用户可以移动鼠标以触发一些JavaScript代码之后,但是在您的ASP代码运行并且它发生在客户端计算机中之后很久。

为了使客户端事件“调用”服务器端代码,您必须触发某种服务器请求。 “form.submit”是客户端JavaScript代码可以调用form.submit函数来提交表单的典型示例,这会导致浏览器将页面回发到服务器,然后再次调用服务器代码,然后生成一些新的HTML并发送回客户端浏览器,然后客户端浏览器就像这样反复接管。

您可以使用AJAX随时在页面中“呼叫”回服务器。 我熟悉ASP.NET AJAX,但我不知道你可以用ASP。 但是这个概念是一样的,你必须以某种方式回到服务器端才能运行服务器端代码。

希望这有点帮助。

You can't really do that that way. The key is the "passing mouse" event occurs on the client machine. Where ASP code runs on the server machine. So you have to have some way to hook them together.

They way that they appear to work together is, When user request an asp page with the browser on their machine, their browser sends a request to your web server, your web server runs your asp code, which generates HTML code. It then send the result HTML code to the client, the client browser receives the result HTML code and then takes over from there. After this user can move the mouse to trigger some JavaScript code, but this is long after your ASP code has run and it happens in the client computer.

In order for a client event to "call" server side code, you would have to trigger some kind of server request. A "form.submit" a typical example where client JavaScript code can call form.submit function to submit the form, which causes the browser to post back the page to the server, then your server code get called again, then it generates some new HTML and send back to the client browser, then the client browser takes over, over and over like this.

You can use AJAX to "call" back to the server any time in your page. I am familiar with ASP.NET AJAX but I do not know what you can use with ASP. However the concept is the same, which is you have to somehow go back to the server side in order to run server side code.

Hope this helps a little bit.

更多推荐

fs,<%,code,%>,电脑培训,计算机培训,IT培训"/> <meta name="descripti

本文发布于:2023-08-06 21:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454953.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:鼠标   代码   经典   ASP   mouse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!