javascript Microsoft JScript 运行时错误:无法获取属性“样式”的值:对象为空或未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12234210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:41:17  来源:igfitidea点击:

Microsoft JScript runtime error: Unable to get value of the property 'style': object is null or undefined

c#javascriptasp.net

提问by user1612076

This is my code line throwing error

这是我的代码行抛出错误

$get("Panel1").style.visibility= "visible";

This line works well on normal page .But whenever using it on child page which owns a master page it throws the error as "Microsoft JScript runtime error: Unable to get value of the property 'style': object is null or undefined". I am a great beginner to javascript . I am using this on Asp.Net 3.5 .Any one know this issue before .

此行在普通页面上运行良好。但每当在拥有母版页的子页面上使用它时,它都会抛出错误“Microsoft JScript 运行时错误:无法获取属性‘样式’的值:对象为空或未定义”。我是一个很棒的 javascript 初学者。我在 Asp.Net 3.5 上使用它。任何人之前都知道这个问题。

采纳答案by Aristos

Your problem is probably because you do not use the rendered id, that is change if you use the same panel on dipper page. And because you do not use the correct id, the $get()part return the null or undefined. Change your code to:

您的问题可能是因为您没有使用呈现的 id,如果您在 dipper 页面上使用相同的面板,则会发生变化。并且因为您没有使用正确的 id,该$get()部分返回null or undefined. 将您的代码更改为:

$get("<%=Panel1.ClientID%>").style.visibility= "visible";

and render the panel1 id as it will final be on the html page.

并呈现 panel1 id,因为它将最终出现在 html 页面上。

What you should have to solve it alone: You could on the page to see the "view page source" from your browser utility and see if the Panel1id exist on your html struct, there you can find what was the correct id and the reason that was not found. So the point here is that we look the html rendered page to find out whats going wrong with the scripts.

您应该单独解决的问题:您可以在页面上从浏览器实用程序中查看“查看页面源代码”,并查看Panel1html 结构中是否存在 id,在那里您可以找到正确的 id 和原因没有找到。所以这里的重点是我们查看 html 呈现的页面以找出脚本出了什么问题。