关闭

CSDN Blog显示页面中的脚本BUG

标签: 脚本blogobject测试
824人阅读 评论(2) 收藏 举报
分类:

取消“禁用脚本调试”,随便打开一个CSDN Blog显示页面,会出现下面的错误:

调试一下发现是下面的代码有问题:

<SCRIPT type=text/javascript>
<!--
var PostComment.ascx_RequiredFieldValidator2 = document.all ? document.all["PostComment.ascx_RequiredFieldValidator2"] : document.getElementById("PostComment.ascx_RequiredFieldValidator2");
PostComment.ascx_RequiredFieldValidator2.controltovalidate = "PostComment.ascx_tbName";
PostComment.ascx_RequiredFieldValidator2.errormessage = "
请输入尊姓大名"; PostComment.ascx_RequiredFieldValidator2.display = "Dynamic"; PostComment.ascx_RequiredFieldValidator2.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid"; PostComment.ascx_RequiredFieldValidator2.initialvalue = ""; var PostComment.ascx_RequiredFieldValidator3 = document.all ? document.all["PostComment.ascx_RequiredFieldValidator3"] : document.getElementById("PostComment.ascx_RequiredFieldValidator3"); PostComment.ascx_RequiredFieldValidator3.controltovalidate = "PostComment.ascx_tbComment"; PostComment.ascx_RequiredFieldValidator3.errormessage = "
请输入评论"; PostComment.ascx_RequiredFieldValidator3.display = "Dynamic"; PostComment.ascx_RequiredFieldValidator3.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid"; PostComment.ascx_RequiredFieldValidator3.initialvalue = ""; // --> </SCRIPT>

错误原因是变量声明,变量名声明为PostComment.ascx_RequiredFieldValidator2不正确。

可以这样实现:

<SCRIPT type=text/javascript>
<!--
var PostComment = new Object();
PostComment.ascx_RequiredFieldValidator2 = document.all ? document.all["PostComment.ascx_RequiredFieldValidator2"] : document.getElementById("PostComment.ascx_RequiredFieldValidator2");
PostComment.ascx_RequiredFieldValidator2.controltovalidate = "PostComment.ascx_tbName";
PostComment.ascx_RequiredFieldValidator2.errormessage = "
请输入尊姓大名"; PostComment.ascx_RequiredFieldValidator2.display = "Dynamic"; PostComment.ascx_RequiredFieldValidator2.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid"; PostComment.ascx_RequiredFieldValidator2.initialvalue = ""; PostComment.ascx_RequiredFieldValidator3 = document.all ? document.all["PostComment.ascx_RequiredFieldValidator3"] : document.getElementById("PostComment.ascx_RequiredFieldValidator3"); PostComment.ascx_RequiredFieldValidator3.controltovalidate = "PostComment.ascx_tbComment"; PostComment.ascx_RequiredFieldValidator3.errormessage = "
请输入评论"; PostComment.ascx_RequiredFieldValidator3.display = "Dynamic"; PostComment.ascx_RequiredFieldValidator3.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid"; PostComment.ascx_RequiredFieldValidator3.initialvalue = ""; // --> </SCRIPT>

又仔细看了一下,好象是回复部分是用ascx用户控件做的,不是手工写的。“PostComment.ascx”是用户控件的ID,大概是这里的问题,建议在aspx中使用ascx时,使用简单名称。

在VS2005下做了个测试,用“PostComment.ascx”作ID是不能编译的,不知道为什么出现这种情况。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:137958次
    • 积分:2086
    • 等级:
    • 排名:第18248名
    • 原创:62篇
    • 转载:0篇
    • 译文:4篇
    • 评论:47条
    最新评论