zoukankan
html css js c++ java
在 可编辑的 Div 的 光标位置 插入 文字 或 HTML
示例代码如下:
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
Div 光标位置 插入 文字 或 HTML
</
title
>
<
script
language
="javascript"
type
="text/javascript"
>
var
pos;
function
getPos()
{
pos
=
document.selection.createRange();
}
function
fn_insertPos()
{
if
(pos
!=
null
)
{
pos.text
=
"
插入文字内容
"
;
//
pos.pasteHTML("<font color='red'>文字内容</font>");
//
pos.pasteHTML("<br/>文本框控件:<input id='Text1' type='text' />");
//
释放位置
pos
=
null
;
}
else
{
alert(
"
没有正确选择位置
"
);
}
}
</
script
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
id
="myDiv"
style
=" 300px; height: 100px;
border: black 1px solid; font-size:small; line-height:1; "
onclick
="getPos();"
onkeyup
="getPos();"
contenteditable
="true"
>
一二三四五六七八
</
div
>
<
input
id
="Button1"
type
="button"
onclick
="fn_insertPos();"
value
="点击本按钮在Div中插入相关内容"
/>
</
form
>
</
body
>
</
html
>
查看全文
相关阅读:
struts 2.1.8.1的sx:datetimepicker标签出现NaN错误的原因和解决办法
php windows与linux下的路径区别
php递归删除文件夹
php ffmpeg截取视频第一帧保存为图片的方法
mysql group by使用方法注意
PHP更新用户微信信息的方法
PHP file_get_contents 读取js脚本的问题
javascript采用Broadway实现安卓视频自动播放的方法(这种坑比较多 不建议使用)
html5 textarea 写入换行的方法
jquery swiper3自定义切换效果的方法
原文地址:https://www.cnblogs.com/freeliver54/p/832492.html
最新文章
随机森林的算法思想
HDU1272:小希的迷宫(并查集)
Codeforces Round #523 (Div. 2) D. TV Shows
Codeforces Round #523 (Div. 2) C. Multiplicity
Codeforces Round #523 (Div. 2) B. Views Matter
Codeforces Round #523 (Div. 2) A. Coins
Codeforces Round #524 (Div. 2) B. Margarite and the best present
Codeforces Round #524 (Div. 2) A. Petya and Origami
Codeforces Round #524 (Div. 2) C. Masha and two friends
Codeforces Round #524 (Div. 2) D. Olya and magical square
热门文章
POJ2492:A Bug's Life(种类并查集)
创建框架链接--frameset的连接方法
创建框架链接--frameset的连接方法
浮动框架iframe
浮动框架iframe
使用框架结构之frameset
使用框架结构之frameset
URI和URL对比
URI和URL对比
struts 2.1.8.1的sx:datetimepicker标签出现NaN错误的原因和解决办法
Copyright © 2011-2022 走看看