用js实现
textare在光标处插入“#请输入话题#”
并且#号里面的文字是选中的,就是微薄的那种插入话题一样的js功能。
textare在光标处插入“#请输入话题#”
并且#号里面的文字是选中的,就是微薄的那种插入话题一样的js功能。
解决方案 »
- 网页会乱跳啊
- nhibernate 数据库存有大量数据的问题
- 请问如何自动生成一个html文件
- ASP截取两字符串中的值存入库
- 大家帮忙看看这个错误 期待ing...
- (郁闷--高手路过请进)求教关于Excel 11.0 Object Library 的使用方法(asp.net+C#)
- 奇怪,我把DLL拷贝到bin目录下后,客户端打开网页,用的还是以前的dll
- asp.net 2.0 新建项目后页面跳转问题
- “"mynamespace._Default""”不是属性“inherits”的有效值。
- 用DataSet怎么调用存储过程?
- 把一个单用户的博客 改成 多用户的博客 需要用到什么技术呢?
- 只能用html和JavaScript做个留言板页面,谁给个思路啊
var tc = document.getElementById("textarea");
var tclen = tc.value.length;
tc.focus();
if(typeof document.selection != "undefined")
{
document.selection.createRange().text = "";
}
else
{
tc.value = tc.value.substr(0,tc.selectionStart)+""+tc.value.substring(tc.selectionStart,tclen);
}
}
,长度不为零就return.我有没有理解错?
r.findText("");
r.select();
<head>
<script type='text/javascript'>
function test(str){ var tc = document.getElementById("mytextarea");
var tclen = tc.value.length;
tc.focus();
if(tc.value.indexOf(str) > 0){
var r=tc.createTextRange();
r.findText("请输入话题内容");
r.select();
return;
}else{
if(typeof document.selection != "undefined")
{
document.selection.createRange().text = str;
}
else
{
tc.value = tc.value.substr(0,tc.selectionStart)+str+tc.value.substring(tc.selectionStart,tclen);
}
var r=tc.createTextRange();
r.findText("请输入话题内容");
r.select();
}}
</script>
</head>
<body>
<textarea rows=5 name=s1 cols=27 id="mytextarea">目的通过点击页面上的按钮button 在textarea中的光标停留处插上文字 </textarea>
<input type=button onclick="test('#请输入话题内容#')" />
</body>
</html>