打印本文 打印本文 关闭窗口 关闭窗口
取得input中部分选中(selected)的值
作者:武汉SEO闵涛  文章来源:敏韬网  点击数882  更新时间:2009/4/23 13:50:31  文章录入:mintao  责任编辑:mintao

      取得input中部分选中(selected)的值(for IE and Firefox),这个例子非常不错,给大家共享一下。

<script language="javascript">
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));

function a(){
var myArea = document.getElementById("s");
var selection;
if (!ie){
if (myArea.selectionStart!= undefined) {
selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart);
}
}else{
if (window.getSelection){
selection = window.getSelection();
}else if (document.getSelection){
selection = document.getSelection();
}else if (document.selection){
selection = document.selection.createRange().text;
}
}
alert(selection)
}

</script>
<input type="text" value="testtest" id="s" name="s"
onmouseup="javascript:a()" />

打印本文 打印本文 关闭窗口 关闭窗口