RSS
热门关键字:
当前位置 :| 主页>美工设计>WEB标准>

取得input中部分选中(selected)的值

来源:网络 作者:佚名 时间:2008-08-28 Tag: 点击:
取得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()" />


上一篇:windows下的忘记MYSQL密码的重设办法
下一篇:没有了
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册