【问题标题】:firebug saying not a function萤火虫说不是功能
【发布时间】:2010-05-25 08:32:18
【问题描述】:
<script type = "text/javascript">
        var First_Array = new Array();
        function reset_Form2() {document.extraInfo.reset();}
        function showList1() {document.getElementById("favSports").style.visibility="visible";}
        function showList2() {document.getElementById("favSubjects").style.visibility="visible";}
        function hideProceed() {document.getElementById('proceed').style.visibility='hidden';}

    function proceedToSecond ()
    {
        document.getElementById("div1").style.visibility="hidden";
        document.getElementById("div2").style.visibility="visible";
        document.getElementById("favSports").style.visibility="hidden";
        document.getElementById("favSubjects").style.visibility="hidden";
    }

    function backToFirst () {
        document.getElementById("div1").style.visibility="visible";
        document.getElementById("div2").style.visibility="hidden";
        document.getElementById("favSports").style.visibility="visible";
        document.getElementById("favSubjects").style.visibility="visible";
    }

    function reset_Form(){
        document.personalInfo.reset();
        document.getElementById("favSports").style.visibility="hidden";
        document.getElementById("favSubjects").style.visibility="hidden";
    }

    function isValidName(firstStr) {
        var firstPat = /^([a-zA-Z]+)$/;

        var matchArray = firstStr.match(firstPat);
        if (matchArray == null) {
            alert("That's a weird name, try again");
            return false;
        }

        return true;
    }

    function isValidZip(zipStr) {
        var zipPat =/[0-9]{5}/;
        var matchArray = zipStr.match(zipPat);
        if(matchArray == null) {
            alert("Zip is not in valid format");
            return false;
        }
        return true;
    }

    function isValidApt(aptStr) {
        var aptPat = /[\d]/;
        var matchArray = aptStr.match(aptPat);
        if(matchArray == null) {
            if (aptStr=="") {
                return true;
            }
            alert("Apt is not proper format");
            return false;
        }

        return true;
    }

    function isValidDate(dateStr) {
        //requires 4 digit year:

        var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

        var matchArray = dateStr.match(datePat);
        if (matchArray == null) {
            alert("Date is not in a valid format.");
            return false;
        }
        return true;
    }

    function checkRadioFirst() {
        var rb = document.personalInfo.salutation;

        for(var i=0;i<rb.length;i++) {
            if(rb[i].checked) {
                return true;
            }
        }
        alert("Please specify a salutation");
        return false;
    }

    function checkCheckFirst() {
        var rb = document.personalInfo.operatingSystems;

        for(var i=0;i<rb.length;i++) {
            if(rb[i].checked) {
                return true;
            }
        }
        alert("Please specify an operating system") ;
        return false;
    }

    function checkSelectFirst() {
        if ( document.personalInfo.sports.selectedIndex == -1)
        {
            alert ( "Please select a sport" );
            return false;
        }
        return true;
    }

    function checkRadioSecond() {
        var rb = document.extraInfo.referral;

        for(var i=0;i<rb.length;i++) {
            if(rb[i].checked) {
                return true;
            }
        }

        alert("Please select form of referral");
        return false;
    }

    function checkCheckSecond() {
        var rb = document.extraInfo.officeSupplies;

        for(var i=0;i<rb.length;i++) {
            if(rb[i].checked) {
                return true;
            }
        }
        alert("Please select an office supply option");
        return false;
    }

    function checkSelectSecond() {
        if ( document.extraInfo.colorPick.selectedIndex == 0 ) {
            alert ( "Please select a favorite color" );
            return false;
        }
        return true;
    }

    function check_Form(){
        var retvalue = isValidDate(document.personalInfo.date.value);
        if(retvalue) {

            retvalue = isValidZip(document.personalInfo.zipCode.value);
            if(retvalue) {

                retvalue = isValidName(document.personalInfo.nameFirst.value);
                if(retvalue) {

                    retvalue = checkRadioFirst();
                    if(retvalue) {

                        retvalue = checkCheckFirst();
                        if(retvalue) {

                            retvalue = checkSelectFirst();
                            if(retvalue) {

                                retvalue = isValidApt(document.personalInfo.aptNum.value);
                                if(retvalue){
                                    document.getElementById('proceed').style.visibility='visible';

                                    var rb = document.personalInfo.salutation;

                                    for(var i=0;i<rb.length;i++) {
                                        if(rb[i].checked) {
                                            var salForm = rb[i].value;
                                        }
                                    }

                                    var SportsOptions = "";
                                    for(var j=0;j<document.personalInfo.sports.length;j++){
                                        if ( document.personalInfo.sports.options[j].selected){
                                            SportsOptions += document.personalInfo.sports.options[j].value + " ";
                                        }
                                    }

                                    var SubjectsOptions= "";
                                    for(var k=0;k<document.personalInfo.subjects.length;k++){
                                        if ( document.personalInfo.subjects.options[k].selected){
                                            SubjectsOptions += document.personalInfo.subjects.options[k].value + " ";
                                        }

                                    }

                                    var osBox = document.personalInfo.operatingSystems;
                                    var OSOptions = "";
                                    for(var y=0;y<osBox.length;y++) {
                                        if(osBox[y].checked) {
                                            OSOptions += osBox[y].value + " ";
                                        }
                                    }


                                    First_Array[0] = salForm;
                                    First_Array[1] = document.personalInfo.nameFirst.value;
                                    First_Array[2] = document.personalInfo.nameMiddle.value;
                                    First_Array[3] = document.personalInfo.nameLast.value;
                                    First_Array[4] = document.personalInfo.address.value;
                                    First_Array[5] = document.personalInfo.aptNum.value;
                                    First_Array[6] = document.personalInfo.city.value;
                                    for(var l=0; l<document.personalInfo.state.length; l++) {
                                        if (document.personalInfo.state.options[l].selected) {
                                            First_Array[7] = document.personalInfo.state[l].value;
                                        }
                                    }
                                    First_Array[8] = document.personalInfo.zipCode.value;
                                    First_Array[9] = document.personalInfo.date.value;
                                    First_Array[10] = document.personalInfo.phone.value;
                                    First_Array[11] = SportsOptions;
                                    First_Array[12] = SubjectsOptions;
                                    First_Array[13] = OSOptions;

                                    alert("Everything looks good.");
                                    document.getElementById('validityButton').style.visibility='hidden';
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    /*function formAction2() {
        var retvalue;
        retvalue = checkRadioSecond();
        if(!retvalue) {
            return retvalue;
        }

        retvalue = checkCheckSecond();
        if(!retvalue) {
            return retvalue;
        }

        return checkSelectSecond() ;
    }   */
</script>

这只是代码示例,还有更多功能,但我认为错误可能与周围代码有关。我完全不知道为什么,因为我知道所有周围的函数都会执行,并且 First_Array 已填充。

但是,当我单击 Proceed to Second 按钮时,onclick 属性不会执行,因为 Firebug 说proceedToSecond 不是函数

按钮代码:

<input type="button" id="proceed" name="proceedToSecond" onclick="proceedToSecond();" value="Proceed to second form">

【问题讨论】:

  • 你能显示“继续第二个”按钮的 HTML 吗?
  • 这个 sn-p 请求重构 ;)

标签: html forms firebug javascript


【解决方案1】:

我遇到了同样的问题,这是因为您有一个与您的函数同名的表单。 JavaScript 似乎无法区分这两者,因此您会收到“不是函数”错误。

【讨论】:

  • 如果您尝试将全局变量命名为“status”,则会发生相同类型的事情,但它因浏览器而异。如果你问我,这真的很愚蠢。
【解决方案2】:

在您给出的 sn-p 之前,您的 Javascript 中可能存在错误。如果是这样,其余的将不会被 Firefox 解析,然后你的函数将不会被定义。

【讨论】:

  • 我刚刚展示了所有代码.. 虽然这里有点乱。顶部有一个
  • 如果你的JS代码有问题,Firefox的错误控制台肯定有输出。它说什么?
【解决方案3】:

通过在调用和函数名称中将proceedToSecond() 更改为doIt() 解决了问题。我不知道为什么

【讨论】:

  • 这表示某种冲突,您能否将整个源代码粘贴到某个地方,最好是在pastebin.com 上?
【解决方案4】:

嗯...我总是使用javascript:function_name() 而不是function_name(),因为有几次javascript 没有运行。 html sn-p 可能 的名称标签必须更改为稍微不同的名称,因为 javascript 可能会混淆它。您能否向我们展示整个 javascript 文件,因为底部/顶部某处可能存在错误/语法错误。

【讨论】:

    【解决方案5】:

    当您将代码插入空的 html 文档 (&lt;html&gt;&lt;head/&gt;&lt;body&gt; code &lt;/body&gt;&lt;/html&gt;) 时,它可以在我的计算机 Firefox 3.5.5、Firebug 1.4.3 上运行

    也许您的 DOM 中的某个地方或您的某些其他函数中存在另一个错误?

    您能否将整个源代码粘贴到此处,或者粘贴到 pastebin 网站上?

    【讨论】:

      猜你喜欢
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多