找到Javascript错误 [英] Javascript error found

查看:96
本文介绍了找到Javascript错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < script    类型  =  text / javascript    language   =  javascript   >  

函数ValidateField(sender,args){
if (document.getElementById( <% = TextBox2.ClientID%>)。 value == ){
alert( 请输入数量< /跨度>);
document.getElementById( <%= TextBox2.ClientID%>)。焦点();
return false ;
}

for var i = 0 ; i < = 20 ; i ++)
{
var txtbox = document.getElementById( Textbox + i)

if (txtbox)
{

if (txtbox。 value != null && txtbox。 value .trim()==
{

alert( Serial数字字段不能为空);

return false ;

}

}

}

}

< / script >

< br $>
Hello Everyone

在上面的代码中,输入数量正常,但输入序列号显示以下错误

Microsoft JScript运行时错误:对象不支持此属性或方法。

请帮助

解决方案

同样的情况发生在我身上。可能是使用IE.so基本上将你的javascript代码放在最后,或者你正在使用jquery然后在


(document).ready。



检测值之前检测它是否为空或不是对象。

将代码放入try catch块



 尝试 {
- ;
}
catch (呃){
throw ex;
}





请参阅以下链接

MSDN Microsfot

W3学校


请参阅有关检查jQuery返回的值的讨论:http://stackoverflow.com/questions/3247251/is-ifdocument-getelementbyidsomething-null-identical-to- ifdocument-getel [ ^ ]。



同时,无需检查 txtbox.value!= null 对于任何真正存在的文本框:它可以是空字符串,而不是空。



-SA

<script type="text/javascript" language="javascript" >

      function ValidateField(sender, args) {
         if (document.getElementById("<%= TextBox2.ClientID%>").value == "") {
             alert("Please enter the quantity");
             document.getElementById("<%=TextBox2.ClientID %>").focus();
             return false;
         }

         for (var i = 0; i <= 20; i++)
         {
             var txtbox = document.getElementById("Textbox" + i)

             if (txtbox)
              {

                  if (txtbox.value != null && txtbox.value.trim() == "") 
                 {

                     alert("Serial Number field cannot be empty");

                     return false;

                 }

             }

         }

    }    
     
   </script>


Hello Everyone
In my code above, it is working fine for enter quantity but for enter serial number it is showing the following error
Microsoft JScript runtime error: Object doesn't support this property or method.
Kindly help

解决方案

The same situation occured with me.Yoy Might be using IE.so basically place your javascript code in the end or if you are using jquery then under


(document).ready.

Before Detecting value detect whther it is not null or not an object.
Place your code in try catch block

try{
--;
}
catch(er){
throw ex;
}



Refer the following link
MSDN Microsfot
W3 schools


Please see this discussion on checking up the values returned by jQuery: http://stackoverflow.com/questions/3247251/is-ifdocument-getelementbyidsomething-null-identical-to-ifdocument-getel[^].

At the same time, there is no need to checkup txtbox.value != null for any really existing text box: it can be empty string, not null.

—SA


这篇关于找到Javascript错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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