yaocheap.com
域名年龄: 12年9个月13天HTTP/1.1 200 OK 访问时间:2016年03月06日 08:03:46 服务器:Apache/2 语言环境:PHP/5.3.29 X-Pingback: http://www.yaocheap.com/xmlrpc.php 动作:Accept-Encoding,User-Agent Content-Encoding: gzip 文件大小:20669 Keep-Alive: timeout=1, max=100 连接:Keep-Alive 类型:text/html; charset=UTF-8 网站编码:UTF-8
鷇惪駬狂热的技术爱好者MenuSkip to content首页PHP技术javascript/jqueryMYSQL技术PHP二次开发易企记事狗算法碎碎念js/jquery在div中光标位置插入图片2016年2月24日2016年2月24日 by 码壹<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Language" content="zh-cn" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>DIV可编辑框鼠标光标处插入图片或者文字。</title><script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script><script type="text/javascript">$(function(){$(".imgbox img").click(function(){$("#testdiv").focus();var sy = $(".imgbox img").index(this) + 1;var img_url = "<img src='faceimg/"+sy+".gif'>";/*此处如果不是插入图片可这样:var img_url = "插入测试的文字";*/_insertimg(img_url);})//注:如果要插入的是那种“快捷发言,快捷留言”里的文字,只需把那些文字都分别放在A标签里即可,然后img_url=a标签里面的内容。工作中的编辑器终于搞定!能插入图片和快捷发言和表情图片等。})//监控粘贴(ctrl+v),如果是粘贴过来的东东,则替换多余的html代码,只保留<br>function pasteHandler(){setTimeout(function(){var content = document.getElementById("testdiv").innerHTML;valiHTML=["br"]; content=content.replace(/_moz_dirty=""/gi, "").replace(/\[/g, "[[-").replace(/\]/g, "-]]").replace(/<\/ ?tr[^>]*>/gi, "[br]").replace(/<\/ ?td[^>]*>/gi, " ").replace(/<(ul|dl|ol)[^>]*>/gi, "[br]").replace(/<(li|dd)[^>]*>/gi, "[br]").replace(/<p [^>]*>/gi, "[br]").replace(new RegExp("<(/?(?:" + valiHTML.join("|") + ")[^>]*)>", "gi"), "[$1]").replace(new RegExp('<span([^>]*class="?at"?[^>]*)>', "gi"), "[span$1]").replace(/<[^>]*>/g, "").replace(/\[\[\-/g, "[").replace(/\-\]\]/g, "]").replace(new RegExp("\\[(/?(?:" + valiHTML.join("|") + "|img|span)[^\\]]*)\\]", "gi"), "<$1>");if(!$.browser.mozilla){content=content.replace(/\r?\n/gi, "<br>");}document.getElementById("testdiv").innerHTML=content;},1);}//锁定编辑器中鼠标光标位置。。function _insertimg(str){var selection= window.getSelection ? window.getSelection() : document.selection;var range= selection.createRange ? selection.createRange() : selection.getRangeAt(0);if (!window.getSelection){document.getElementById('testdiv').focus();var selection= window.getSelection ? window.getSelection() : document.selection;var range= selection.createRange ? selection.createRange() : selection.getRangeAt(0);range.pasteHTML(str);range.collapse(false);range.select();}else{document.getElementById('testdiv').focus();range.collapse(false);var hasR = range.createContextualFragment(str);var hasR_lastChild = hasR.lastChild;while (hasR_lastChild && hasR_lastChild.nodeName.toLowerCase() == "br" && hasR_lastChild.previousSibling && hasR_lastChild.previousSibling.nodeName.toLowerCase() == "br") {var e = hasR_lastChild;hasR_lastChild = hasR_lastChild.previousSibling;hasR.removeChild(e);} range.insertNode(hasR);if (hasR_lastChild) {range.setEndAfter(hasR_lastChi
© 2010 - 2020 网站综合信息查询 同IP网站查询 相关类似网站查询 网站备案查询网站地图 最新查询 最近更新 优秀网站 热门网站 全部网站 同IP查询 备案查询
2024-04-18 11:56, Process in 0.0064 second.