求助JS高手,怎样获取input文本框中高亮显示的值?
例如:
<input name= "aa " value= "abcdefgh "> ,选取了 "bcd ",怎么通过JS来获取“bcd”
------解决方案--------------------if(document.all){
var content = document.selection.createRange();
}else{
var content = window.getSelection();
content.text = content.toString();
}
var str = content.text;//选择的内容
------解决方案-------------------- <input value= "dsafsdafweqrqwerwqer ">
<button onclick= "alert(document.selection.createRange().text) "> ssss </button>
------解决方案--------------------selection对象的操作
------解决方案--------------------借萝卜的
<input value= "dsafsdafweqrqwerwqer " type=text onmouseup=sel()>
<script>
function sel(){
if(document.all){
var content = document.selection.createRange();
}else{
var content = window.getSelection();
content.text = content.toString();
}
var str = content.text;//选择的内容
ss.innerText = str;
}
</script>
<span id=ss> </span>