日期:2014-05-17  浏览次数:20530 次

asp.net C#如何得到textbox选定的文本
RT
比如说这是内容
怎么得到选定的文本‘内容’?


------解决方案--------------------
只能通过JS获取
后台要使用可AJAX来实现

JS代码
function getRangeById(id) 

var word=''; 
if (document.selection){o=document.selection.createRange();if(o.text.length>0)word=o.text;}else{ 
o=document.getElementById(id); p1=o.selectionStart;p2=o.selectionEnd; 
if (p1||p1=='0'){if(p1!=p2)word=o.value.substring(p1,p2);}} 
return word;