回答
您可以删除表中直接使用格式字符串substr()
var myString = "smth <table>asdasdasd</table>smth else";
var firstPart = myString.substr(0,myString.indexOf('<table>'));
var secondPart = myString.substr(myString.lastIndexOf('</table>')+8);
myString = firstPart + secondPart;
UPD并从DOM移除台我会或者使用jQuery的方法:
$(document).ready(function(){
$('#tableId').remove();
})
或纯JS:
var table = document.getElementById('tableId');
table.parentNode.removeChild(table);
这应该工作,我会试试看。 – 2014-10-28 11:45:58
删除表似乎对我来说还好。你等待DOM加载,你可以使用$(文件)。就绪(),或在window.onload
window.onload = function() {
var table = document.getElementById("fileTable");
table.innerHTML = 'I removed the table';
console.log(table);
}
看完原来你有一个大括号缺少全码:
<script type="text/javascript">
function privateComment(){
var file = 0;
var message = document.getElementById("commentPrivate").innerHTML;
if(message.indexOf("contenteditable") > -1){
var table = document.getElementById("fileTable");
var type = table.getAttribute("type");
var file_id = table.getAttribute("fileId");
var taskId = table.getAttribute("taskId");
table.innerHTML = '';
var string = string + '{"type": "' + type + '", "file_id": "' + file_id + '", "taskId": "' + taskId + '"}';
var file = 1;
} // <<< THIS IS NOT THE LAST BRACE
var taskId = document.getElementById('form-task-title').getAttribute('showing');
var button = document.getElementById("submit-private-comment");
alert(message);
} //<<ADD THIS BRACE .
</script>
感谢您的帮助,但在pastebin的底部我放置了“//在此处切断了代码”。下次我会更清楚一点。再次感谢! – 2014-10-28 11:53:35
NP - 如果您要提供代码,请提供完整的上下文 - 或将其创建为小型,以便其他人可以将其提取并运行(我花了大约20分钟才能将它们合并到一起!) – 2014-10-28 12:23:24
- 1. 获取json字符串元素
- 2. 获取PARAM和元素的字符串
- 3. 从字符串中提取元素
- 4. 获取元素从符号
- 5. 如何使用jQuery从字符串获取HTML元素
- 6. JQuery从字符串问题中获取元素
- 7. 如何从字符串中获取特定元素
- 8. 从字符串文件中获取特定元素
- 9. 从HTML表格中的选定元素获取源字符串
- 10. 从字符串数组C中获取元素组#
- 11. 从字符串数组获取元素通过拆分法
- 12. 获取从字符串arraylist中删除和添加的元素
- 13. 从html文件上传元素获取base64字符串
- 14. AngularJS从字符串中获取dom元素
- 15. 如何通过索引从分隔字符串获取元素?
- 16. 从字符串获取子字符串__
- 17. 从字符串获取LCID
- 18. 从字符串获取DateTime
- 19. 从字符串获取URL
- 20. 从EditText获取字符串
- 21. 从spinner获取字符串
- 22. 从字符串获取NSDate
- 23. PHP从字符串获取
- 24. 从字符串获取keyCode?
- 25. 从CodeBehind获取字符串
- 26. 从字符串获取JSONObject
- 27. 从Json获取字符串
- 28. 从UILabel获取字符串
- 29. 从字符串获取值?
- 30. 从字符串中读取字符或从字符串中获取字符
你能表现出更多的代码? – 2014-10-28 11:24:48
@ Stuart.Sklinar当然,pastebin传入! – 2014-10-28 11:26:24
难道你不能在这里添加(或者至少更多)吗?它给了整个事情更多的上下文....? – 2014-10-28 11:28:43