ASP.NET 将 Response.Write 与 JavaScript 相结合的编程

ASP.NET programming combining Response.Write with JavaScript

本文关键字:JavaScript 相结合 编程 Write NET Response ASP      更新时间:2023-09-26

我是 ASP.NET 新手。现在我正在修改我们网站中的一些元素。我的页面显示了 n 张图片。单击每个图像时,将在页面上写入另一组图像,该图像基于单击的图像。因此,使用以下代码。

for i=1 to n
response.write"<img src="&SourceFile&" id="&i&" onClick=func(this)>"
next

我的函数代码如下

newSrc="myweb.com/Images/img1.gif"
function func(x)
{
     switch(parseInt(x.id))
     {
          case 1:x.src=newSrc;
                 break;
      }
 }

当我检查时,我发现错误 X 为 null 或不是对象。你能帮我发现错误吗...

你需要 this.id

response.write"<img src="&SourceFile&" id='"&i&"' onClick='func(this.id)'>"

确保您的函数<script></script>客户端