<textarea cols=50 rows=10 id=demo>
1)如果textarea中有一篇文章,我想选种一段文字然后对期进行javascript操作,
请问怎么样取得选种的文字的值?
2)javascipt中使用prompt怎么样在文章中间,也就是获得焦点处添加文字!
</textarea>
<input type=button value=替换选中的文字 onclick=p()>
<script>
function p(){
demo.focus();
with(document.selection.createRange())
text=prompt("请输入要替换的文字,当前是",text)
}
</script>
1)如果textarea中有一篇文章,我想选种一段文字然后对期进行javascript操作,
请问怎么样取得选种的文字的值?
2)javascipt中使用prompt怎么样在文章中间,也就是获得焦点处添加文字!
</textarea>
<input type=button value=替换选中的文字 onclick=p()>
<script>
function p(){
demo.focus();
with(document.selection.createRange())
text=prompt("请输入要替换的文字,当前是",text)
}
</script>
function setEmail()
{
var str =document.selection.createRange().text;
document.form1.content.focus();
var the_value=prompt("请输入您的Email地址","");
var is_at = the_value.indexOf("@");
var is_at_dot = the_value.indexOf(".");
if (is_at == -1|| is_at_dot==-1)
{
alert('您输入的Email格式不正确');
}else{
if(str.length>0){
if (the_value !=null){
var sel =document.selection.createRange();
sel.text="<a href=\"mailto:"+the_value+"\">"+str+"</a>";
}
}else{
var the_name=prompt("请输入您的姓名(如 gabble 或 [email protected])","")
if (the_value !=null){
var sel =document.selection.createRange();
sel.text="<a href=\"mailto:"+the_value+"\">"+the_name+"</a>";
}
}
}
return;
}