【问题标题】:0x800a138a - JavaScript runtime error: Function expected0x800a138a - JavaScript 运行时错误:预期函数
【发布时间】:2015-01-23 20:47:04
【问题描述】:

我的 ASP.NET 页面中有一个文本框。更改文本框内的值时会触发 javascript 函数。

知道为什么会出现此错误吗?

错误:

0x800a138a - JavaScript 运行时错误:预期函数

ASP.NET 代码:

<asp:TextBox ID="entryRates" Width="80" onChange="return showAlert(this);" runat="server" CssClass="TextBox" />

JS代码:

<script type ="text/javascript" >
   function showAlert(obj) 
   {
      if (document.getElementById("rType").value!="HLDR") 
      {
        iput = obj;
        //numberic value (positive or negative)
        if (isNaN(iput.value))
        {
            alert("The entered rate is not a number");
            return false;
        }
        //today's rate
        tdrate=iput.value 
        //yesterday rate
        if (document.all.item("rType").value!="OTHR") 
        {
            ydrate = iput.parentElement.parentElement.childNodes(2).firstChild.innerText; 
        }
        else
        {
            ydrate = iput.parentElement.parentElement.childNodes(4).firstChild.innerText; 
        }
        //alert ("yesterdaycode = "+ydrate);
        trptg = 1.25  //thresholdPercent
        //alert("thresholdPercent = "+trptg);

      if (tdrate.length == 0)
         {
         tdrate=0
         }

      if (ydrate.length == 0)
         {
         ydrate=0
         }
      totchg = (((tdrate / ydrate) - 1) * 100)

      if (totchg < 0)
         {
         totchg = (totchg * -1)
         signchg=1
         }
      else
         {
         totchg = totchg
         signchg=0
         }

      if (totchg != 100 & totchg > trptg)
         {
         if (signchg==0)
            {var s = "" + Math.round(totchg * 100) / 100}
         else
            {var s = "-" + Math.round(totchg * 100) / 100}
         alert("% Change = "+s)
         }
        }
      }  
      </script>

【问题讨论】:

  • childNodes 是只读属性,不是函数,也不接受参数?

标签: javascript asp.net textbox onchange


【解决方案1】:

.childNodes 是一个“类数组对象”。通过方括号访问它的元素:

ydrate = iput.parentElement.parentElement.childNodes[2].firstChild.innerText; 


旁注:不要使用document.all。这是一个专有的扩展。使用标准方法,例如 document.getElementById(),因为您已经在函数顶部执行了此操作。

【讨论】:

    【解决方案2】:

    最近我遇到了同样的 javascript 运行时错误,它只发生在 IE 中。问题出在我的一个函数名称中。我猜这个名字是在 IE 中保留的。我刚刚重命名了它,问题得到了解决。以防万一,这里是有问题的函数的名称:

    function start(){
    }
    

    改名为:

    function startInstallation(){
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多