在尝试动态删除表行时,得到Uncaught SyntaxError: Unexpected token}
getting Uncaught SyntaxError: Unexpected token } while trying to remove table row dynamically
我在其他线程中寻找了同样的问题,但无法找到解决方案。
我试图克隆表行并通过更改输入字段的索引将其附加到同一表,我还删除了添加字形图标,并用具有onClick
功能的新字形图标替换它,当我试图删除字形图标的点击行时,我得到了这个(Uncaught SyntaxError: Unexpected token})错误。我一遍又一遍地检查我的代码,但没有找到解决方案。
这是我的代码
$(document).ready(function(){
var glyphRemove="";
glyphRemove="<span class='glyphicon glyphicon-minus glyph_size' id='remove' onClick='$(this).closest('tr').remove()' aria-hidden='true'></span>";
$("#add").click(function() {
var clone= $("#cloneObject").clone();
clone.removeClass('hide');
clone.prop('disabled',false);
clone.find('#add').remove();
clone.find('#glyph').append(glyphRemove);
clone.appendTo("#shiftsTable");
});
});
当我将onClick
函数更改为onClick=$this.parent().parent().remove()
时,它工作得非常好,并删除包含字形图标的td
部分。
我哪里说错了
此处:
glyphRemove="<span class='glyphicon glyphicon-minus glyph_size' id='remove' onClick='$(this).closest('tr').remove()' aria-hidden='true'></span>";
$("#add").click(function() {
var clone= $("#cloneObject").clone();
clone.removeClass('hide');
clone.prop('disabled',false);
clone.find('#add').remove();
clone.find('#glyph').append(glyphRemove);
clone.appendTo("#shiftsTable");
}
^
});
。
你的代码应该像这样:
$(document).ready(function(){
var glyphRemove="";
glyphRemove="<span class='glyphicon glyphicon-minus glyph_size' id='remove' onClick='$(this).closest('tr').remove()' aria-hidden='true'></span>";
$("#add").click(function() {
var clone= $("#cloneObject").clone();
clone.removeClass('hide');
clone.prop('disabled',false);
clone.find('#add').remove();
clone.find('#glyph').append(glyphRemove);
clone.appendTo("#shiftsTable");
});
});
相关文章:
- Uncaught SyntaxError:尝试读取json数据时出现意外数字
- 为什么JSON.parse()在尝试解析一个简单的JSON对象时抛出Uncaught SyntaxError:意外的令牌
- PHP调用脚本函数,返回值为Uncaught SyntaxError:意外的令牌ILLEGAL
- Uncaught SyntaxError:在剑道网格中动态生成列时出现意外数字
- Snap.svg and javascript throws Uncaught SyntaxError
- 我在这里得到了Uncaught SyntaxError:意外的令牌<.为什么会这样
- 是什么导致了$.parseJSON()和JSON.parse()的“Uncaught SyntaxError:意外令牌o
- jQuery AJAX POST请求抛出Uncaught SyntaxError:意外标识符
- 为什么我会得到Uncaught SyntaxError:意外的令牌非法
- ajaxt weird error: Uncaught SyntaxError: Unexpected token if
- index.php:13 Uncaught SyntaxError: Unexpected token: Ci中的错误消
- 试图调用JS函数并获得Uncaught SyntaxError: Unexpected identifier
- Uncaught SyntaxError: ajax jquery的意外标识符
- 接收错误"Uncaught SyntaxError: Unexpected token "用Shin
- React JS应用程序- Uncaught SyntaxError: Unexpected token <
- 尝试使用标记的模板字符串给出'Uncaught SyntaxError: Unexpected token
- Javascript for循环返回“Uncaught SyntaxError: Unexpected Token <&
- 在尝试动态删除表行时,得到Uncaught SyntaxError: Unexpected token}
- Javascript和Chrome调试器:"Uncaught SyntaxError: Unexpected
- AngularJS Flickr API 'Uncaught SyntaxError: Unexpected t