jQuery巨大的selectbox导致Uncaught RangeError:超过了最大调用堆栈大小
jQuery huge selectbox result in Uncaught RangeError: Maximum call stack size exceeded
我有一个选择框,选择"其他"选项后,将显示第二个选择框(超过10k的巨大列表)。这在IE和Mozilla中运行良好,但在Chrome中达到了未捕获的范围错误。如何调试和修复此问题?
<!DOCTYPE html>
<html>
<body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#thisIsTheSelectBox').change(function() {
var otherSelectBoxId = $(this).attr('id') + "xyz123";
if ($(this).val() === "Others") {
var otherSelectBox = "<select id='" + otherSelectBoxId + "' name='' unit='' uniquename='' class=' ' required='true'> " +
"<option value='option 1'>option 1</option>" +
"<option value='option 2'>option 2</option>" +
...
"<option value='option 10000'>option 10000</option>" +
"</select>";
$(this).after(otherSelectBox);
} else {
$("#" + otherSelectBoxId).remove();
}
});
});
</script>
</head>
<table>
<tr>
<td width="330" valign="top">
<select id="thisIsTheSelectBox" name="" required="true">
<option value=''>-- Options --</option>
<option value='1'>test1</option>
<option value='2'>test2</option>
<option value='Others'>Others</option>
</select>
</td>
</tr>
</table>
</body>
这可能是一个内部错误。您可以在循环中添加每个元素,而不是构建一个长字符串,这样代码将更轻、更易于维护。
代码:
$(document).ready(function () {
$('#thisIsTheSelectBox').change(function () {
var otherSelectBoxId = $(this).attr('id') + "xyz123";
if ($(this).val() === "Others") {
var otherSelectBox = "<select id='" + otherSelectBoxId + "' name='' unit='' uniquename='' class=' ' required='true'> ";
for (var i = 0; i <= 10000; i++) {
otherSelectBox += "<option value='option" + i + "'>option " + i + "</option>";
}
otherSelectBox += "</select>";
$(this).after(otherSelectBox);
} else {
$("#" + otherSelectBoxId).remove();
}
});
});
演示:http://jsfiddle.net/IrvinDominin/4gk5zd5t/
相关文章:
- Javascript在实现时似乎跳过了一行(如果count==1)
- 我需要迭代一个JSON数组——不知道如何做到——已经搜索过了,但仍然可以'我一点也不知道
- Hammer.js过了一段时间就停止工作了
- grunt contrib jshint-error在定义之前就已经使用过了
- 进行自动实时聊天/虚假聊天,我的javascript跳过了第一个响应
- 正在跳过Ajax调用
- 如果我丢失了调用对象,如何杀死 setInterval()/setTimout()
- 再次调用时跳过了 Ajax
- Mootools 类扩展了调用重写的父方法
- 我试过了,但调用成员单击不适用于输入按钮,它与其他按钮非常不同
- 窗口位置不起作用,我已经尝试过了
- 引导程序下拉不起作用.什么都试过了..(引导2.3.2)
- 为什么将一个值推入我的数组被跳过了
- 七吃九:为什么我的索引8在这个d3选择中被跳过了
- 为什么这个复选框不触发jquery代码onchange?我什么都试过了,但都不起作用
- 尽管通过id进行了调用,但Javascript无法访问jsf outputText(label)元素
- jQuery不工作-'jQuery在定义之前就已经使用过了;
- getElementById有时为null.已经试过了.加载完毕.准备好了
- Javascript跳过函数调用中的参数
- AJAX调用跳过了发送一些参数,或者PHP丢失了一些参数