展会信息港展会大全

取得input中部分选中(selected)的值
来源:互联网   发布日期:2016-03-25 16:42:31   浏览:2411次  

导读: 取得input中部分选中(selected)的值(for IE and Firefox),这个例子非常不错,给大家共享一下。代码如下复制代码 function P...

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

代码如下

复制代码

function Preview(obj)

{

var TestWin=open('');

TestWin.document.write(obj.value);

}

function copyCode(obj) {

var rng = document.body.createTextRange();

rng.moveToElementText(obj);

rng.scrollIntoView();

rng.select();

rng.execCommand("Copy");

rng.collapse(false);

}

function saveCode(obj) {

var winname = window.open('', '_blank', 'top=10000');

winname.document.open('text/html', 'replace');

winname.document.writeln(obj.value);

winname.document.execCommand('saveas','','homepage..htm');

winname.close();

}

function addBookmark(title,url) {

if (window.sidebar) {

window.sidebar.addPanel(title, url,"");

} else if( document.all ) {

window.external.AddFavorite(url,title);

} else if( window.opera && window.print ) {

return true;

}

}

<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()" />

运行代码复制代码另存代码收藏本页

赞助本站

人工智能实验室

相关热词: 开发 编程 android

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港