【杯具】javascript无法执行

xupeihuagudulei 2010-07-06 03:53:41

<script type="text/javascript">
//<![CDATA[
confirm('当前报表已存在,是否取出?提示:点击确定取出已存在报表,取消则重新创建报表。')?document.getElementById('btnReCreateNo').click():document.getElementById('btnReCreateYes').click();//]]>


这是 在html页面生成的js为什么无法执行。
详细错误信息:

/*网页错误详细信息

用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
时间戳: Tue, 6 Jul 2010 07:53:18 UTC


消息: 'document.getElementById(...)' 为空或不是对象
行: 103
字符: 1
代码: 0
URI: http://localhost/xmes_develop/CustomReport/RtdbReportView.aspx?ResourceId=e8260767-1c17-4102-bd34-c3d62f807113&ZonePath=0%2fe8260767-1c17-4102-bd34-c3d62f807113

*/

主要问题是在上个帖子链接
http://topic.csdn.net/u/20100706/10/02b9d891-4340-48d5-9d90-d78a3f8c0505.html


...全文
276 42 打赏 收藏 转发到动态 举报
写回复
用AI写文章
42 条回复
切换为时间正序
请发表友善的回复…
发表回复
xupeihuagudulei 2010-07-06
  • 打赏
  • 举报
回复
非哥,用你那两个button的方法搞定了。
就是后台代码感觉乱而已
呵呵。
骑猪看海 2010-07-06
  • 打赏
  • 举报
回复
不是告诉你了吗

消息: 'document.getElementById(...)' 为空或不是对象

把代码放在'document.getElementById(...)后执行
fuda_1985 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 30 楼 xupeihuagudulei 的回复:]

引用 29 楼 w3c5201314 的回复:

设置客户端display为none
那当我第一次访问页面的时候button总还得显示。
只有执行操作才可以把button的display给设置为none..
PS:display 设置为none html源码里还会不会存在此元素?
[/Quote]
会存在,但是后台设的话前台没有。
w3c5201314 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 37 楼 w3c5201314 的回复:]
string confirmJs = string.Format("document.getElementById('{0}').style.display='none';document.getElementById('{1}').style.display='none';", btnReCreateNo.ClientID, btnReCreateYes.ClientID);
Client……
[/Quote]
窗体加载,load方法中调用
w3c5201314 2010-07-06
  • 打赏
  • 举报
回复
string confirmJs = string.Format("document.getElementById('{0}').style.display='none';document.getElementById('{1}').style.display='none';", btnReCreateNo.ClientID, btnReCreateYes.ClientID);
ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm", confirmJs, true);
w3c5201314 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 31 楼 cpp2017 的回复:]
我在JS中在没有function的情况下用document.getElementById获取数据,报未定义,但document.all却可以,所以不得不这么想。
===>
可能是因为你的控件的id不是这个id而是用name

document.all.控件name也是可以的,document.getElementById只能用id
[/Quote]
我也怀疑过,当时是我控件名称搞错了,或是存在重复了。后来单独测试,还是这样,就搞不懂ASP的规则了,真怀疑到底是机器出问题还是.....
xupeihuagudulei 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 34 楼 w3c5201314 的回复:]

引用 30 楼 xupeihuagudulei 的回复:
引用 29 楼 w3c5201314 的回复:

设置客户端display为none
那当我第一次访问页面的时候button总还得显示。
只有执行操作才可以把button的display给设置为none..
PS:display 设置为none html源码里还会不会存在此元素?

你的空间是事先定义好了的还是动态加载的?……
[/Quote]事先定义的
w3c5201314 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 30 楼 xupeihuagudulei 的回复:]
引用 29 楼 w3c5201314 的回复:

设置客户端display为none
那当我第一次访问页面的时候button总还得显示。
只有执行操作才可以把button的display给设置为none..
PS:display 设置为none html源码里还会不会存在此元素?
[/Quote]
你的空间是事先定义好了的还是动态加载的?
display只设置显影性,代码中会存在此空间。
事先定义好的,在窗口加载时就设置,否则在动态加载时设置
阿非 2010-07-06
  • 打赏
  • 举报
回复
好久不见慕白兄 ~
cpp2017 2010-07-06
  • 打赏
  • 举报
回复
PS:display 设置为none html源码里还会不会存在此元素?
===>存在,可以访问,但是服务器控件visible设为false在客户端就不存在了.
cpp2017 2010-07-06
  • 打赏
  • 举报
回复
我在JS中在没有function的情况下用document.getElementById获取数据,报未定义,但document.all却可以,所以不得不这么想。
===>
可能是因为你的控件的id不是这个id而是用name

document.all.控件name也是可以的,document.getElementById只能用id
xupeihuagudulei 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 29 楼 w3c5201314 的回复:]

设置客户端display为none
[/Quote]那当我第一次访问页面的时候button总还得显示。
只有执行操作才可以把button的display给设置为none..
PS:display 设置为none html源码里还会不会存在此元素?
w3c5201314 2010-07-06
  • 打赏
  • 举报
回复
设置客户端display为none
xupeihuagudulei 2010-07-06
  • 打赏
  • 举报
回复
但是把button给弄出来,我界面样式就乱了
就多这两个button

把width设置为0px还是有占空间的。
这怎么解决呢?
xupeihuagudulei 2010-07-06
  • 打赏
  • 举报
回复
噢,我知道了
我那两个btnCreateYes和btnCreateNO的visible属性设置为false....
w3c5201314 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 cpp2017 的回复:]
w3c5201314

==>
不是不能这样用,是因为你理解的不正确.

document.getElementById是标准的取html元素的用法,document.all是只有ie才能用的方法ms特定的,
这与在不在funtion中一点关系都没有,你这样会误导别人.
[/Quote]
多谢指点,我知道是document.getElementById是标准获取,document.all获取较广。
但我开发ASP.net网站时的确遇到这样的问题,我在JS中在没有function的情况下用document.getElementById获取数据,报未定义,但document.all却可以,所以不得不这么想。
xupeihuagudulei 2010-07-06
  • 打赏
  • 举报
回复
我贴下我错误的aspx页面的html

<script type="text/javascript">
//<![CDATA[
confirm('当前报表已存在,是否取出?提示:点击确定取出已存在报表,取消则重新创建报表。')?document.getElementById('btnReCreateNo').click():document.getElementById('btnReCreateYes').click();//]]>
</script>


<script type="text/javascript" src="../JS/CustomReport/ReportView.js">
reportView.js内容为:


var waiting_win;
function OpenWaiting() {
waiting_win = window.open('../waiting.aspx', 'WaitingWin', 'left='
+ (screen.availWidth - 300) / 2 + ',top='
+ (screen.availHeight - 200) / 2 + ',width=300,height=200');
}
function window_OnUnLoad() {
alert(waiting_win);
if (typeof (waiting_win) != "undefined" && waiting_win != null) {
try {
waiting_win = window.open('../waiting.aspx', 'WaitingWin', 'left='
+ (screen.availWidth - 300) / 2 + ',top='
+ (screen.availHeight - 200) / 2 + ',width=300,height=200');
waiting_win.opener = null;

waiting_win.close();
}
catch (ex) { }
}
}

</script>

<script type="text/javascript">

function $(o) { return document.getElementById(o); }
window.onresize = resizeDivHtmlReport;
function resizeDivHtmlReport() {
$("divHtmlReport").style.height = self.document.body.clientHeight - 55;
}

var canCloseWindow = "true", isEnterButton;

function CanCloseWindow() {
if (canCloseWindow == "false") {
window.event.returnValue = "报表正在生成中, 离开当前页面将影响页面的正常浏览.";
}
if (isEnterButton) {
canCloseWindow = "false";
isEnterButton = false;
}
}
</script>

cpp2017 2010-07-06
  • 打赏
  • 举报
回复
你看看生成的客户端js,然后打js中对应的id,看元素能不能找到.
xupeihuagudulei 2010-07-06
  • 打赏
  • 举报
回复
那这真杯具了
我这里面用了用户控件
还另外用了两三个JS。
加载更多回复(22)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧