错误:"Microsoft JScript运行时错误:需要对象"; [英] Error: "Microsoft JScript runtime error: Object required"

查看:140
本文介绍了错误:"Microsoft JScript运行时错误:需要对象";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码:

Here is the code:

<script language="javascript" type="text/javascript">
    function ChangeImage(FirstID, SecondID) {

        document.write(FirstID + "_" + SecondID);
        var ClickedImage = document.getElementById(FirstID);
        var img = document.getElementById(SecondID);
        var changeURL = img.src;  <--       

        img.src = ClickedImage.src;

        ClickedImage.src = changeURL.src;



    }

</script>



错误"Microsoft JScript运行时错误:必需的对象"跳转
在箭头所在的线上.



The Error "Microsoft JScript runtime error: Object required" jumps
on the line where the arrow is.

How to fix that?

推荐答案

显然,这是因为此时img == null;这是因为在调用img = document.getElementById(SecondID)时没有名称为SecontID的任何元素.您可能计算错了SecondID,或者从未在任何元素中具有期望值的属性id.您的HTML在哪里?

如何使用Javascipt调试器?它可以与Visual Studio一起使用.

-SA
Apparently, this is because img == null at this point; and this is because you don''t have any element with name SecontID at the moment of the call img = document.getElementById(SecondID). You could have miscalculated SecondID or never had attribute id with expected value in any of the elements. Where is your HTML?

How about using Javascipt debugger? It can be used with Visual Studio.

—SA


img.ID的使用请使用img.ClientID
insead of img.ID use img.ClientID


如果它的ImageButton然后设置img.ImageUrl属性
if its a ImageButton then set img.ImageUrl property


这篇关于错误:"Microsoft JScript运行时错误:需要对象";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆