简体   繁体   English

结合Response.Write和JavaScript的ASP.NET编程

[英]ASP.NET programming combining Response.Write with JavaScript

I am new to ASP.NET. 我是ASP.NET的新手。 Now I am in the process of modifying some elements in our site. 现在,我正在修改网站中的某些元素。 My page has n images displayed. 我的页面显示了n张图像。 On clicking each images another set of images will be written on the page which is based on the image clicked. 单击每个图像后,将基于单击的图像在页面上写入另一组图像。 So the following code is used. 因此,使用以下代码。

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

And my function code is as follows 我的功能代码如下

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

when i checked i found the error x is null or not an object. 当我检查时,我发现错误x为null或不是对象。 Can you please help me spot the errors... 您能帮我发现错误吗?

you need to to this.id 您需要this.id

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

make sure that your function is <script></script> client side 确保您的功能是<script></script>客户端

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM