Mee*_*etM 5 html javascript jquery contenteditable
HTML 代码如下所示
<div id="txtarea" contenteditable="true">Some text</div>
Run Code Online (Sandbox Code Playgroud)
我必须根据上述 div 中特定位置的某个事件插入一些新文本。该事件调用函数 say updateDiv(txt, positon)。例如它说
updateDiv("more ",5);
所以div应该变成
<div id="txtarea" contenteditable="true">Some more text</div>
Run Code Online (Sandbox Code Playgroud)
我尝试了很多 javascript 和 jquery,但似乎没有任何效果。
我是这样做的:
\n\nvar position = 5,\n txt = "more ";\nvar current = $("#txtarea").html();\n//alert(current.substring(0, position))\nvar endVal = current.substring(position);\nvar newValue = current.substring(0, position) + txt + endVal;\n$("#txtarea").html(newValue);\xe2\x80\x8b\nRun Code Online (Sandbox Code Playgroud)\n\njsfiddle显示它“正在运行”。
\n\n编辑:使用上面评论中列出的方法更新了jsfiddle到这篇文章。相当光滑!
\n| 归档时间: |
|
| 查看次数: |
6649 次 |
| 最近记录: |