把選擇定內容增加到文字框

來源:互聯網
上載者:User
提示:您可以先修改部分代碼再運行

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.111cn.net/1999/xhtml" lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="Content-Language" content="zh-CN" /><title></title><script type="text/javascript">function $( id ) {var obj = null;obj = document.getElementById(id);return obj ? obj : null;}function show( id ) {$(id).style.display = "block";}function hide( id ){$(id).style.display = "none";}function MouseEvent(e) { this.e = e || window.event; this.x = e.pageX || e.clientX; this.y = e.pageY || e.clientY; this.target = e.target || e.srcElement;}function addListener(type, callback) { if (document.addEventListener) { document.addEventListener(type, callback, false); } else if (document.attachEvent) { document.attachEvent("on"+type, callback, false); }}function removeListener (type, callback) { if (document.removeEventListener) { document.removeEventListener(type, callback, false); } else if (document.detachEvent) { document.detachEvent("on" + type, callback, false); }}function handleDown() {if($('selected')) {$('selected').outerHTML = $('selected').innerHTML;hide('editbox');} addListener("mouseup", handleUp);}function handleUp(e) { var e = new MouseEvent(e);removeListener("mouseup", handleUp);if (window.getSelection) {alert('ݲִ֧IE鿴'); return false;//var str = window.getSelection().toString();} else if (document.getSelection) {alert('ݲִ֧IE鿴'); return false;//var str = document.getSelection().toString();} else if (document.selection) {//IEvar r = document.selection.createRange(); var str = r.text;} if(str != '' && e.target == $('edittext')) {r.execCommand('ForeColor', false, 'red');var regExp = /<font(.*)</font>/i;e.target.innerHTML = e.target.innerHTML.replace(regExp, '<span id="selected" >'+str+'</span>');show('editbox');$('editbox').style.left = e.x + "px";$('editbox').style.top = e.y + "px";$('textarea').value = str;}}function save() { var val = $('textarea').value; $('selected').outerHTML = val;hide('editbox');}</script></head><body><div id="edittext" onmousedown="handleDown();" >把選擇定內容增加到文字框</div><div id="editbox" style = "background: #ddd; position: absolute; border: 1px solid #aaa; width: 300px; height: 150px; padding: 5px; text-align: right; display: none;"><textarea id="textarea" style = "width:295px; height: 120px; border: 1px solid #aaa; margin-bottom: 3px;">
提示:您可以先修改部分代碼再運行

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.