- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8">
<!-- ** JavaScript ** -->
<script src="products.js" charset="utf-8"></script>
<script src="purchased.js" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
clear_table = function( ) {
var table = document.getElementById( "cart_table" );
while(table.hasChildNodes( )) {
table.removeChild( table.firstChild );
}
}
make_table = function( items ) {
// ** Load items into table and calc total **
var total = 0;
var table = document.getElementById("cart_table");
for(var x = 0; x < items.length; x++){
var tr = table.insertRow( x + 1 );
var item = tr.insertCell( 0 );
var price = tr.insertCell( 1 );
item.innerHTML = items[x].name;
price.innerHTML = "$" + items[x].price;
//remove button
var remove_btn = document.createElement( "button" );
remove_btn.className = "btn_remove";
remove_btn.href = "#";
remove_btn.index = x;
var btn_text = document.createTextNode( "x" );
remove_btn.appendChild( btn_text );
var remove = tr.insertCell( 2 );
remove.appendChild( remove_btn );
remove_btn.onclick = function() {
items.delete(this.index);
var ids = new Array();
for( var x = 0; x < items.length; x++ ){
ids.push( items[x].id );
}
save_purchased( ids );
clear_table( );
make_table( items );
return false;
}
//total
total += ( items[x].price );
}//end build table loop
//insert total
var tr = table.insertRow(x+1);
var item = tr.insertCell( 0 );
var price = tr.insertCell( 1 );
item.innerHTML = "Total: ";
price.innerHTML = "$" + total;
}
window.onload = function() {
// ** Get orders id form cookie **
var order = load_purchased();
// ** Load orders products from cookie id into items[] **
var items = new Array();
for( var x = 0; x < order.length; x++ ){
items.push( get_product( order[x] ) );
//alert( items[x].name );
}
make_table( items );
}//end window.onload()
</script>
</head>
<body>
<heading>
<h1>Cart</h1>
<a href="home.html"><button class="btn_cart">← Home</button></a>
</heading>
<div id="content">
<table id="cart_table">
<tr>
<th>Item</th>
<th>Price</th>
<th>Remove</th>
</tr>
</table>
<a href="checkout.html"><button class="btn_cart">Order →</button></a>
</div>
</body>
是什么导致了这个错误? (IndexSizeError
:索引或大小为负数或大于允许的数量)
错误发生在 make_table()
从 remove_link.onclick
事件执行时。
这个 make_table()
函数首先从 window.onload()
执行,它创建了我的表。它执行良好,没有错误。
但是当我点击某个元素旁边的删除按钮将其从表格中删除时。 remove_link.onclick()
执行,它再次执行 make_table()
函数以重新创建没有不需要的元素的表并计算新的总数。
嗯...函数在第二次执行时不起作用,我得到这个错误(IndexSizeError
: Index or size is negative or greater than the allowed amount)
控制台显示它在第 27 行,也就是这一行 (var tr = table.insertRow(x + 1);
)。
但是,我可以刷新页面,页面将再次正常加载,我删除的元素消失了。所以只有当 make_table()
函数从 onclick
事件中被调用时。
最佳答案
我遇到了类似的情况。一遍又一遍地阅读我的代码后,我看到了愚蠢的错误。
let Row = LicenseTableBody.insertRow( rowIndex );
let cell0 = Row.insertCell(0);
// let cell1 = Row.insertCell(1);
let cell2 = Row.insertCell(2);
let cell3 = Row.insertCell(3);
它给了我标题中提到的错误。我想我错误地试图在 0
之后立即在 2
位置插入单元格。这不是一个好的顺序。
所以,我只是将顺序更改为正确的顺序,如下所示:
let Row = LicenseTableBody.insertRow( rowIndex );
let cell0 = Row.insertCell(0);
// let cell1 = Row.insertCell(1);
let cell2 = Row.insertCell(1);
let cell3 = Row.insertCell(2);.
当然,我犯了一个愚蠢的错误。
希望对您有所帮助,
关于javascript - 当我尝试在我的页面上创建表格时出现此错误 - IndexSizeError : Index or size is negative or greater than the allowed amount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40940293/
好吧,虽然模式 [abc] 匹配单个字符 a、b 或 c 时,模式 [^abc] 匹配任何不是的给定字符 a、b 或c. 现在,如果我在上面的语句中用 string 替换 character,如果我还
我正在学习 Haskell atm,现在我找到了这个功能 const const (negate 1) (negate 2) 3 这个函数的结果是 -2 .我不明白为什么结果不是 -2。 const
我可以有 /[abcd]/、/(ab|cd)/ 和 /[^wxyz]/。为什么不是 /(^wx|yz)/ Apparently您可以通过简单地将功能与其他功能组合在一起来实现完全相同的效果,如下所示:
我正在尝试在我的 C++ 14 代码中执行一个简单的操作 pow(-0.89,-0.67),它给出了一个 NaN 作为结果。在 SciLab 中执行相同操作时,结果为 -1.08。在 C++ 中有什么
我又在与正则表达式作斗争了。我一直在尝试添加使用转义字符来转义自定义标记,例如 至 和 至 .在乔治的帮助下,here , 在尝试转义方法之前,以下表达式会产生所需的结果。 ('This is a
我使用三个值(=页数)A , B , C对于属性(property)is of type . 某些页面只有一个值 is of type ,某些页面具有所有三个值。 我想要#ask对于类型为 A 的页面
我正在尝试使用普罗米修斯数据源在 Grafana 中绘制条形图。 我的简单查询如下所示: max_over_time(energy_monitor_watthour_today[1d]) 我将 Gra
我正在尝试使用 if GNU 中的函数(与条件语句之一相反)make如果未定义特定变量,则为了将单词添加到列表中。我最终这样做的方法是将第二个参数留空,同时提供第三个参数,如下所示: FOO := b
以下程序应打印数组元素的总和是正数还是负数: #include #define ARR_SIZE 5 int main() { int array[ARR_SIZE] = {1,-2,3,4,
我试图在公式中替换所有缺少前面零的 float 。例如: “4+.5”应该变成:“4+0.5” 现在我读到 JavaScript 不支持向后看,那么我该如何实现呢?当前面有数字时,以下代码也会替换:
我有这个 64x64 二维数组 该阵列的数据可在此处下载 - http://m.uploadedit.com/ba3s/1494223164755.txt 现在,我想复制这个数组,其中具有最高值的区域
我在研究 String 及其构造函数时发现了一些我无法解释的行为。 我创建了以下方法 public static String negate(String s) { byte[] b = s.
我在我的应用程序的 Crashlytics 中看到了这次崩溃。我不知道哪里出了问题。 有人对为什么会发生这种崩溃有任何建议吗? Fatal Exception: java.lang.IllegalAr
我有一些异常值的数据集,例如以下 x <- rnorm(1000,0,20) x <- c(x, 500, -500) 如果我们以此绘制在线性x轴刻度上,我们将看到 histogram(x) 我想出了
tl;dr:我该如何做类似下面编写的代码的事情: def notFunctor[M[_] : Not[Functor]](m: M[_]) = s"$m is not a functor" 'Not[
我有一个程序可以替换文件中的内容。但是却导致了IO异常,我不知道我哪里逻辑错了? 代码如下: import java.io.File; import java.io.RandomAccessFile;
我正在验证整数是否为零或更大。将需求描述为“零或更大”感觉过于冗长。说“非负面”会引入负面语言,我会尽量避免。 在描述必须为零或更大的值时,您使用什么简洁的描述符? 最佳答案 positiveValu
我使用的是tinyMCE版本3,我使用的是富文本编辑器,它会在输入时计算剩余的字符数。由于 maxLength 属性不适用于tinyMCE3。我已经以这种方式进行了硬编码,但它也计算了空白字符
下面的示例在调用look_back_1()或look_back_2()时应该崩溃。原因:当对无符号变量求反时,结果应保持无符号。 #include int look_back_1(int *arr,
虽然我阅读了大量有关该主题的文章(特别是使用环视),但我不明白是否可以使用正则表达式解决这种更一般的情况。 设置: 1) 在 中传递了一个输入正则表达式2) 输入正则表达式嵌入到负正则表达式中,这样
我是一名优秀的程序员,十分优秀!