too much recursion

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        label{
            color: rgba(231, 117, 231, 0.91);
        }
        select{
            width: 100px;
            color: blue;
        }
    </style>
</head>
<body>
    <label for="">省份</label>
    <select name="" id="province" onchange="onchange()">
        <option value=""id="op">请选择省份</option>
        <option value="" id="op1" >四川</option>
        <option value="" id="op2" >重庆</option>
        <option value="" id="op3" >山东</option>
    </select>
    <br/><br/>
    <label for="">城市</label>
    <select name="" id="city"></select>

    <script>
        var province = document.getElementById("province");
        var city = document.getElementById("city");
        var op = document.getElementById("op");
        op.selected=true;
        function onchange(){
            if(province.selectedIndex==1){
                for(var i=city.children.length;i>=0;i--){
                    city.remove(i);
                }
                var allCity = ["成都","南充","绵阳"];
                for(var i =0;i<allCity.length;i++ ){
                    city.options.add(new Option(allCity[i],allCity[i]));
                }
            }else if(province.selectedIndex==2){
                for(var i=city.children.length;i>=0;i--){
                    city.remove(i);
                }
                var allCity= ["万州","丰都","九龙坡"]
                for(var i =0;i<allCity.length;i++ ){
                    city.options.add(new Option(allCity[i],allCity[i]));
                }

            }else if(province.selectedIndex==3){
                for(var i=city.children.length;i>=0;i--){
                    city.remove(i);
                }
                var allCity =["济南","青岛","烟台"];
                for(var i=0;i<allCity.length;i++){
                    city.options.add(new Option(allCity[i],allCity[i]));
                }
            }
        }
    </script>
</body>
</html>

运行这个JS在FF中会出现too much recursion错误,而在IE中会出现Stack Overflow错误,
困惑我不少时间,经过搜索得知:
原来JS的关键字不可以用来作为函数名的。
所以解决方法是:把onchange函数名改为其他不是关键字的就行了。

时间: 2024-08-11 03:35:40

too much recursion的相关文章

Python的最大递归深度错误 “maximum recursion depth exceeded while calling a Python object”

今天在写爬虫的时候,发现了一个诡异的事情,使用str方法强制转换一个BeautifulSoup对象成字符串的时候报错了,提示是"maximum recursion depth exceeded while calling a Python object",意思大致是"当调用该对象超过最大递归深度" 报错如下:   Traceback (most recent call last):   File "<stdin>", line 1, 

Scala Learning(3): Tail Recursion定义

关于尾递归 ,使用Scala的两个例子展示尾递归的定义和简单实现. 例子比较 求最大公约数的函数 def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b) 计算的展开是尾递归的, gcd(14, 21) -> if (21 == 0) 14 else gcd(21, 14 % 21) -> if (false) 14 else gcd(21, 14 % 21) -> gcd(21, 14 % 21) -> gcd

递归和迭代(Recursion and Iteration)

递归 特点:简而言之,递归就是应用程序调用自身.所以,存在预期收敛,才能使用递归(因为不能无限期递归调用下去). 优点:程序看着比较简单,比较容易实现. 缺点:递归要占用额外的栈空间,如果递归的深度比较大,那么占用的栈比较多,而且调用函数的时间也比较多,时空性都不好. 所以选择递归要考虑好处和缺点之间的权衡. 迭代 特点:通过步号寻找需要的信息,经典的例子比如C++中的for循环语句(迭代遍历程序). 优点:开销只因循环的增加而相应增加,没有额外的空间开销和时间开销. 缺点:编写复杂问题时可能程

Recursion

Recursion It is legal for one function to call another; it is also legal for a function to call itself. It may not be obvious why what is a good thing, but it turns out to be one of the most magical things a program can do. For example: If a recursio

数据结构与算法5: 递归(Recursion)

数据结构与算法5: 递归(Recursion) 写在前面 <软件随想录:程序员部落酋长Joel谈软件>一书中<学校只教java的危险性>一章提到,大学计算机系专业课有两个传统的知识点,但许多人从来都没搞懂过,那就是指针和递归.我也很遗憾没能早点熟练掌握这两个知识点.本节一些关键知识点和部分例子,都整理自教材或者网络,参考资料列在末尾.如果错误请纠正我. 思考列表: 1)什么程序具有递归解决的潜质? 2)递归还是非递归算法,怎么选择? 3)递归程序构造的一般模式 1.递归定义 首要引

递归(recursion)

人分两种:男人和女人:算法分两种:递归的和迭代/循环的:递归是指用自己的较简单的情形定义自己. 在数学和计算机科学中,递归是一种思路和策略,可以用于术语的定义(什么是表达式),问题的描述和问题求解.用于问题求解的递归称为递归法. 有一个故事.物理学家计算10!时会说,"看,它等于1*2*-*10,即3628800":数学家则说:"哦,10的阶乘,它等于10乘以9!". 递归算法"轻率地"认为自己的较简单的情形是已知的.既然fact(n-1)是已知

Java Tail Recursion

Recursion.      /**      * sum from 1 to n. recursion      * @param i      * @return sum       */     public int recur_head(int i){         System.out.println("i = "+ i);         if(i==1)             return 1;         else             return i+r

Atitit &#160;循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate).

Atitit  循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate). 1.1. 循环算是最基础的概念, 凡是重复执行一段代码, 都可以称之为循环. 大部分的递归, 遍历, 迭代, 都是循环.1 1.2. 递归的定义是, 根据一种(几种)基本情况定义的算法, 其他复杂情况都可以被逐步还原为基本情况.1 1.3. 递归的基本概念和特点1 1.4. 迭代(数学): 在循环的基础上, 每一次循环, 都比上一次更为接近结果.2 1.5. 编程语言中的循环

Jan 16 - Search Insert Position; Array; Binary Search; Iteration&amp;Recursion;---Iteration再补上

Recursion: 代码: public class Solution { public int searchInsert(int[] nums, int target) { int len = nums.length; if(len == 0) return 0; return findPosition(nums, 0, len-1, target); } public int findPosition(int[] nums, int start, int end, int target){

Go by Example: Recursion

Go语言支持递归函数.这里是一个经典例子:factorial 数列. package main import "fmt" // fact函数不断地调用自身,直到达到基本状态fact(0) func fact(n int) int { if n == 0 { return 1 } return n * fact(n-1) } func main() { fmt.Println(fact(7)) } 输出 <span style="font-size:18px;"