Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript-使用document.execcommand将行添加到现有表中,但我犯了一些错误,但我没有';我不知道它在哪里_Javascript - Fatal编程技术网

Javascript-使用document.execcommand将行添加到现有表中,但我犯了一些错误,但我没有';我不知道它在哪里

Javascript-使用document.execcommand将行添加到现有表中,但我犯了一些错误,但我没有';我不知道它在哪里,javascript,Javascript,我正在开发编辑器,但这个范围的概念我不明白。 我想使用exec命令添加表的第一行。我在下面插入了一张图片 函数addRow(){ 让range=document.createRange(); 让sel=window.getSelection(); 设el=document.querySelector(“tbody”); 开始之前的范围(el.firstChild); 范围。塌陷(真); 选择removeAllRanges(); 选择添加范围(范围); 设b=` 玛丽 教育部 mary@exa

我正在开发编辑器,但这个范围的概念我不明白。 我想使用exec命令添加表的第一行。我在下面插入了一张图片

函数addRow(){
让range=document.createRange();
让sel=window.getSelection();
设el=document.querySelector(“tbody”);
开始之前的范围(el.firstChild);
范围。塌陷(真);
选择removeAllRanges();
选择添加范围(范围);
设b=`
玛丽
教育部
mary@example.com
`;
document.execCommand(“insertHTML”,false,b);
}

名字
姓氏
电子邮件
约翰
雌鹿
john@example.com
玛丽
教育部
mary@example.com
七月
杜利
july@example.com
添加行
您可以使用将HTML文本插入到任何位置

函数addRow(){
设el=document.querySelector(“tbody”);
让newRow=getRow([“玛丽”,“莫伊”,“莫伊”)mary@example.com"]);
el.insertAdjacentHTML(“afterbegin”,newRow);
}
函数getRow(dataArray){
让rowData=dataArray.map(data=>`${data}`)。join(“”);
返回`${rowData}`;
}

名字
姓氏
电子邮件
约翰
雌鹿
john@example.com
玛丽
教育部
mary@example.com
七月
杜利
july@example.com

添加行
是否始终要添加新行作为表的第一行?或者取决于光标所在的行?HI@Terry我希望当前光标点使用document.execcommand()添加行。HI@Mohammad Faisal我希望使用document.execcommand()@SanthoshD添加行。但是为什么要使用document.execcommand(),因为这是MDN声明的Obselete功能。您可以在此处看到文档,嗨@Mohamam Faisal我试过了,但我有一个关于使用execcommad添加行的错误。你能帮助我吗。