欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

自己寫的兼容ie和ff的在線文本編輯器類似ewebeditor

 更新時間:2012年12月12日 10:59:15   投稿:whsnow  
最近寫了個在線的編輯器,類似ewebeditor那樣的,當(dāng)然沒有人家那么強(qiáng)大,但是基本功能都有,而且還是兼容ie和ff的,需要的朋友可以參考下

怎么說呢,剛包完夜吧,應(yīng)該很累了,但現(xiàn)在仍有力氣敲打著這些字符,看來我還沒有到此為止啊。
廢話少說,最近寫了個在線的編輯器,類似ewebeditor那樣的,當(dāng)然沒有人家那么強(qiáng)大,但是基本功能都有,而且還是兼容ie和ff的,為此我也花了不少功夫,還是趕緊把代碼祭出來吧
demo.html

復(fù)制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script src="core.js"></script>
<script src="advance.js"></script>
<table border="0" width="800" height="500" bgcolor="gray">
<tr height="50"><td>
字體:<select onchange="FontName(this.options[this.selectedIndex].value)">
<option value="宋體">宋體
<option value="黑體">黑體
<option value="楷體_GB2312">楷體
<option value="仿宋_GB2312">仿宋
<option value="隸書">隸書
<option value="幼圓">幼圓
<option value="新宋體">新宋體
<option value="細(xì)明體">細(xì)明體
<option value="Arial">Arial
<option value="Arial Black">Arial Black
<option value="Arial Narrow">Arial Narrow
<option value="Bradley Hand ITC">Bradley Hand ITC
<option value="Brush Script MT">Brush Script MT
<option value="Century Gothic">Century Gothic
<option value="Comic Sans MS">Comic Sans MS
<option value="Courier">Courier
<option value="Courier New">Courier New
<option value="MS Sans Serif">MS Sans Serif
<option value="Script">Script
<option value="System">System
<option value="Times New Roman">Times New Roman
<option value="Viner Hand ITC">Viner Hand ITC
<option value="Verdana">Verdana
<option value="Wide Latin">Wide Latin
<option value="Wingdings">Wingdings</option>
</select>
字號:<select onchange="FontSize(this.options[this.selectedIndex].value)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
<button onclick="color()">顏色</button>
<button onclick="bold()">加粗</button>
<button onclick="italic()">傾斜</button>
<button onclick="left()">居左</button>
<button onclick="center()">居中</button>
<button onclick="right()">居右</button>
</td></tr>
<tr height="50"><td>
</td></tr>
<tr height="400">
<td height="400">
<iframe id="content" width="100%" height="100%"></iframe>
</td>
</tr>
</table>
<script src="edit.js"></script>
</body>
</html>

core.js
復(fù)制代碼 代碼如下:

sx={};
sx.comm={};
sx.comm.string=function(){
if(!String.prototype.left){
String.prototype.left=function(l){
return this.substr(0,l);
}
}
if(!String.prototype.right){
String.prototype.right=function(l){
return this.substr(this.length-l,l);
}
}
if(!String.prototype.trim){
String.prototype.trim=function(){
return this.replace(/^/s+|/s+$/g,"");
}
}
}();
sx.comm.array=function(){
if(!Array.prototype.indexOf){
Array.prototype.indexOf=function(data){
for(var i=0;i<this.length;i++){
if(this[i]==data){
break;
}
}
return i==this.length?-1:i;
}
}
if(!Array.prototype.lastIndexOf){
Array.prototype.lastIndexOf=function(data){
for(var i=this.length-1;i>=0;i--){
if(this[i]==data){
break;
}
}
return i;
}
}
if(!Array.prototype.clone){
Array.prototype.clone=function(){
var temp=[];
for(var i=0;i<this.length;i++){
if(this[i] instanceof Array){
temp[i]=this[i].clone();
}else{
temp[i]=this[i];
}
}
return temp;
}
}
if(!Array.prototype.every){
Array.prototype.every=function(o,f){
for (var i = 0; i < this.length; i++) {
if (this[i] instanceof Array) {
this[i].every(o,f);
}
else {
f.call(o, this[i]);
}
}
}
}
}();
sx.comm.ver=function(){
try{
HTMLElement;
return "ff";
}catch(e){
return "ie";
}
}();
sx.comm.ext=function(){
if(sx.comm.ver=="ff"){
HTMLElement.prototype.__defineGetter__("outerHTML",function(){
var attr;
var attrs=this.attributes;
var str="<"+this.tagName.toLowerCase();
for(var i=0;i<attrs.length;i++){
attr=attrs[i];
if(attr.specified)
str+=" "+attr.name+'="'+attr.value+'"';
}
if(!this.canHaveChildren)
return str+">";
return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
});
HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
switch(this.tagName.toLowerCase()){
case "area":
case "base":
case "basefont":
case "col":
case "frame":
case "hr":
case "img":
case "br":
case "input":
case "isindex":
case "link":
case "meta":
case "param":
return false;
}
return true;
});
XMLDocument.prototype.selectNodes = Element.prototype.selectNodes = function (){
//alert(arguments[0]);
var oNSResolver = this.createNSResolver(this.documentElement)
var aItems = this.evaluate(arguments[0].toLowerCase(), this, oNSResolver,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
var aResult = [];
for( var i = 0; i < aItems.snapshotLength; i++)
{
aResult[i] = aItems.snapshotItem(i);
}
//alert(aItems.snapshotLength);
return aResult;
}
}
}();
sx.event={};
sx.event.target=function(){
if(window.event){
return window.event.srcElement;
}else{
var f=arguments.callee.caller;
while(f){
if(f.arguments[0] instanceof Event){
return f.arguments[0].target;
}
f=f.caller;
}
}
}
sx.event.event=function(){
if (window.event) {
return window.event;
}else{
var f=arguments.callee.caller;
while (f) {
if (f.arguments[0] instanceof Event) {
return f.arguments[0];
}
f = f.caller;
}
}
}
sx.event.relatedtarget=function(){
if(window.event){
if(window.event.type=="mouseover"){
return window.event.fromElement;
}else if(window.event.type=="mouseout"){
return window.event.toElement;
}
}else{
var f=arguments.callee.caller;
while (f) {
if (f.arguments[0] instanceof Event) {
return f.arguments[0].relatedTarget;
}
f = f.caller;
}
}
}
sx.event.stopevent=function(){
if (window.event) {
window.event.returnValue=false;
window.event.cancelBubble=true;
}else{
var f=arguments.callee.caller;
while(f){
if(f.arguments[0] instanceof Event){
break;
}
f=f.caller;
}
f.arguments[0].preventDefault();
f.arguments[0].stopPropagation();
}
}
sx.event.addevent=function(e,t,f){
if(!arguments.callee.event){
arguments.callee.event=[];
}
if(e.attachEvent){
e.attachEvent("on"+t,f);
}else{
e.addEventListener(t,f,false);
}
arguments.callee.event.push(f);
return arguments.callee.event.length-1;
}
sx.event.removeevent=function(e,t,i){
if(e.detachEvent){
e.detachEvent("on"+t,sx.event.addevent.event[i]);
}else{
e.removeEventListener(t,sx.event.addevent.event[i],false);
}
sx.event.addevent.event[i]=null;
}
sx.event.parseevent=function(e,t){
if (sx.comm.ver=="ie"){
e.fireEvent("on"+t);
}else{
var evt = document.createEvent("Events");
evt.initEvent(t, true, true);
e.dispatchEvent(evt);
}
}
sx.dom={};
sx.dom.text=function(e){
return this.e.innerText?this.e.innerText:this.e.innerHTML.replace(//<.*?/>/igm,"");
}
sx.dom.elementnodes=function(e,flag){
var temp=[];
var a=e.childNodes;
for(var i=0;i<a.length;i++){
if(a[i].nodeType==flag){
temp.push(a[i]);
}
}
return temp;
}
sx.dom.elementallnodes=function(e,flag){
var temp=[];
var a=e.getElementsByTagName("*");
for(var i=0;i<a.length;i++){
if(a[i].nodeType==flag){
temp.push(a[i]);
}
}
return temp;
}
sx.dom.xpath=function(e,mode){
p=e.cloneNode(true);
var s=p.getElementsByTagName("script");
for(var i=0;i<s.length;i++)
p.replaceChild(s[i].cloneNode(false),s[i]);
var html=p.outerHTML.replace(//=(?!"|')(.*?)(?=/s|>)/ig,"=/"$1/"");
if(window.ActiveXObject){
var x=new ActiveXObject("Msxml2.DOMDocument");
x.async=false;
x.loadXML("<?xml version=/"1.0/" encoding=/"gb2312/" ?>"+html);
}else{
var oParser = new DOMParser();
//alert(html);
var x = oParser.parseFromString(html,"text/xml");
//alert(x.documentElement.tagName);
}
var div=x.selectNodes(mode);
//alert(div.length);
var temp=[];
var a1=x.selectNodes(e.tagName.toUpperCase()+"//*");
//alert(a1.length);
var all=e.getElementsByTagName("*");
//alert(all.length);
var i1=0;
for(i=0;i<a1.length;i++){
//alert(i);
if(a1[i]==div[i1]){
temp.push(all[i]);
i1++;
}
}
x=null;
return temp;
}
sx.dom.left=function(e){
if(document.getBoundingClientRect){
return e.getBoundingClientRect().left;
}else{
var a=e;
var left=0;
while(a){
left+=a.offsetLeft;
a=a.offsetParent;
}
return left;
}
}
sx.dom.top = function(e){
if(document.getBoundingClientRect){
return e.getBoundingClientRect().top;
}else{
var a=e;
var top=0;
while(a){
top+=a.offsetTop;
a=a.offsetParent;
}
return top;
}
}
sx.dom.getstyle=function(e,prop){
if(e.currentStyle){
return e.currentStyle[prop];
}else{
return document.defaultView.getComputedStyle(e,null).getPropertyValue(prop);
}
}
sx.dom.setstyle=function(e,data){
for(var i in data){
e.style[i]=data[i];
}
}
advance.js:
var $=function(id){
return document.getElementById(id);
}

edit.js
復(fù)制代碼 代碼如下:

var w=$("content").contentWindow;
w.document.designMode="on";
w.document.open();
w.document.write("<html><body bgcolor='white'></body></body>")
w.document.close();
if(sx.comm.ver=="ie"){
//w.document.body.style.lineHeight="10px";
}
w.document.onkeydown=function(){
if(sx.comm.ver=="ie"){
if(w.event.keyCode==13){
var s=w.document.selection.createRange();
s.pasteHTML("<br/>");
w.focus();
return false;
}
}
}
function wnd(){
var main=document.createElement("div");
sx.dom.setstyle(main,{
position:"absolute",
width:"100%",
height:"100%",
backgroundColor:"lightblue",
filter:"alpha(opacity=50)",
opacity:0.5
});
var body=document.createElement("div");
sx.dom.setstyle(body,{
position:"absolute",
width:"200px",
height:"250px",
backgroundColor:"green",
zIndex:1000
});
var title=document.createElement("div");
sx.dom.setstyle(title,{
width:"200px",
height:"20px",
backgroundColor:"blue",
});
var close=document.createElement("span");
sx.dom.setstyle(close,{
marginLeft:"180px",
display:"block",
width:"20px",
height:"20px",
textAlign:"center",
cursor:"pointer"
});
close.innerHTML="X";
close.onclick=function(){
main.parentNode.removeChild(main);
body.parentNode.removeChild(body);
}
title.appendChild(close);
body.appendChild(title);
var content=document.createElement("div");
sx.dom.setstyle(content,{
width:"200px",
height:"230px"
});
body.appendChild(content);
this.show=function(e){
document.body.appendChild(main);
sx.dom.setstyle(main,{
top:"0px",
left:"0px"
});
document.body.appendChild(body);
sx.dom.setstyle(body,{
top:sx.dom.top(e)+e.clientHeight+"px",
left:sx.dom.left(e)+e.clientWidth+"px",
});
}
this.close=close;
this.main=main;
this.body=body;
this.title=title;
this.content=content;
}
function bold(){
w.document.execCommand("bold",null,null);
}
function italic(){
w.document.execCommand("italic",null,null);
}
function left(){
w.document.execCommand("JustifyLeft",null,null);
}
function center(){
w.document.execCommand("Justifycenter",null,null);
}
function right(){
w.document.execCommand("Justifyright",null,null);
}
function FontName(value){
w.document.execCommand("FontName", false, value);
}
function FontSize(value){
w.document.execCommand("FontSize", false, value);
}
function inserthr(){
if(document.selection){
w.focus();
var s=w.document.selection.createRange();
s.pasteHTML("<hr/>");
}else{
w.focus();
var s=w.getSelection().getRangeAt(0);
s.insertNode(w.document.createElement("hr"));
}
}
function insertlink(){
if (document.selection) {
w.focus();
var s = w.document.selection.createRange();
}
else {
w.focus();
var s = w.getSelection().getRangeAt(0);
}
var e=sx.event.target();
var ww=new wnd();
ww.content.appendChild(document.createTextNode("請輸入鏈接地址;"));
var link=document.createElement("input");
link.type="text";
link.size=20;
ww.content.appendChild(link);
var b=document.createElement("button");
b.innerHTML="確定";
ww.content.appendChild(b);
b.onclick=function(){
if(sx.comm.ver=="ie"){
s.pasteHTML("<a href='"+link.value+"'>"+s.htmlText+"</a>");
}
else{
var a=w.document.createElement("a");
a.href=link.value;
s.surroundContents(a);
}
sx.event.parseevent(ww.close,"click");
}
ww.show(e);
}
function inserttable(){
if (document.selection) {
w.focus();
var s = w.document.selection.createRange();
}
else {
w.focus();
var s = w.getSelection().getRangeAt(0);
}
var e=sx.event.target();
var ww=new wnd();
ww.content.appendChild(document.createTextNode("請輸入行數(shù);"));
var tr=document.createElement("input");
tr.type="text";
tr.size=20;
ww.content.appendChild(tr);
ww.content.appendChild(document.createElement("br"));
ww.content.appendChild(document.createTextNode("請輸入列數(shù);"));
var td=document.createElement("input");
td.type="text";
td.size=20;
ww.content.appendChild(td);
ww.content.appendChild(document.createElement("br"));
ww.content.appendChild(document.createTextNode("請輸入單元格高度;"));
var height=document.createElement("input");
height.type="text";
height.size=20;
ww.content.appendChild(height);
ww.content.appendChild(document.createElement("br"));
ww.content.appendChild(document.createTextNode("請輸入單元格寬度;"));
var width=document.createElement("input");
width.type="text";
width.size=20;
ww.content.appendChild(width);
ww.content.appendChild(document.createElement("br"));
var b=document.createElement("button");
b.innerHTML="確定";
ww.content.appendChild(b);
b.onclick=function(){
var l1=Number(tr.value);
var l2=Number(td.value);
var h1=Number(height.value);
var w1=Number(width.value);
ww.content.appendChild(document.createTextNode("請輸入單元格高度;"));
var t=document.createElement("table");
t.border="1";
var tb=document.createElement("tbody");
t.appendChild(tb);
for(var i=0;i<l1;i++){
var tr1=document.createElement("tr");
for(var i1=0;i1<l2;i1++){
var td1=document.createElement("td");
td1.innerHTML="";
sx.dom.setstyle(td1,{
width:w1+"px",
height:h1+"px"
});
tr1.appendChild(td1);
}
tb.appendChild(tr1);
}
if(sx.comm.ver=="ie"){
s.pasteHTML(t.outerHTML);
}
else{
s.insertNode(t);
s.insertNode(document.createElement("br"));
}
sx.event.parseevent(ww.close,"click");
}
ww.show(e);
}
function color(){
var e=sx.event.target();
if (document.selection) {
w.focus();
var s = w.document.selection.createRange();
}
else {
w.focus();
var s = w.getSelection().getRangeAt(0);
}
var ww=new wnd();
var colors = ["00","33","66","99","CC","FF"];
var cp=document.createElement("span");
sx.dom.setstyle(cp,{
display:"inline-block",
width:"10px",
height:"10px",
margin:"2px"
});
for(var i1=5;i1>=0;i1--){
for(var i2=5;i2>=0;i2--){
for(var i3=5;i3>=0;i3--){
var cp1=cp.cloneNode(true);
cp1.style.backgroundColor="#" + colors[i1] + colors[i2] + colors[i3];
cp1.title="#" + colors[i1] + colors[i2] + colors[i3];
cp1.onclick=function(){
if(sx.comm.ver=="ie"){
w.focus();
s.pasteHTML("<font color='"+this.title+"'>"+s.htmlText+"</font>");
}
else{
var a=w.document.createElement("font");
a.color=this.title;
s.surroundContents(a);
}
sx.event.parseevent(ww.close,"click");
}
ww.content.appendChild(cp1);
}
}
}
ww.show(e);
}

關(guān)鍵是demo.html和edit.js里的代碼,core.js和advance.js里的代碼是我為兼容瀏覽器寫的,本想把它擴(kuò)展成一個完善的框架的,因?yàn)闀r間有限,就沒寫下去了。

本編輯器還沒有實(shí)現(xiàn)圖片和文件的上傳,因?yàn)樾枰?wù)器技術(shù),所以我就沒寫了,可以交給讀者慢慢研究。
我打算先將web放放了,開始專心于vc++的探究上,盡量能寫出一個像樣的程序出來,以后如果有時間我也會繼續(xù)完善這個編輯器以及javascript兼容的框架。
恩,好好加油吧。

相關(guān)文章

  • HTML很火的浪漫愛心表白代碼

    HTML很火的浪漫愛心表白代碼

    程序員的你是不是也想送個特別的禮物。今天給大家分享一個HTML+CSS+jQuery實(shí)現(xiàn)的情侶浪漫愛心表白JS特效,視覺效果還是相當(dāng)不錯!得此表白神器,程序猿也可以很浪漫!快去追你的女神吧,把這個告白愛心動畫發(fā)給你心愛的她!
    2023-01-01
  • 百度手寫板代碼JavaScript遠(yuǎn)程調(diào)用的實(shí)現(xiàn)(鼠標(biāo)輸入法)

    百度手寫板代碼JavaScript遠(yuǎn)程調(diào)用的實(shí)現(xiàn)(鼠標(biāo)輸入法)

    百度手寫板代碼JavaScript遠(yuǎn)程調(diào)用的實(shí)現(xiàn),其實(shí)沒什么可參考的,引用百度的Js文件,如果大家想使用這個類的話,自己下載就行了,正好可參考一下本演示,幫你快速入題。
    2010-09-09
  • Js檢測判斷URL網(wǎng)址輸入是否正確

    Js檢測判斷URL網(wǎng)址輸入是否正確

    JavaScript檢測判斷用戶輸入的URL是否正確,簡單的正則規(guī)則,很準(zhǔn)確的判斷URL的合法性,值得借鑒。
    2010-10-10
  • 自己寫的兼容ie和ff的在線文本編輯器類似ewebeditor

    自己寫的兼容ie和ff的在線文本編輯器類似ewebeditor

    最近寫了個在線的編輯器,類似ewebeditor那樣的,當(dāng)然沒有人家那么強(qiáng)大,但是基本功能都有,而且還是兼容ie和ff的,需要的朋友可以參考下
    2012-12-12
  • 一款雙向無縫+按鈕定位的焦點(diǎn)圖實(shí)現(xiàn)代碼

    一款雙向無縫+按鈕定位的焦點(diǎn)圖實(shí)現(xiàn)代碼

    做這個焦點(diǎn)圖弄了大個晚上,感覺挺暈的~發(fā)上來給大家踩一下吧 雙向無縫的原理很簡單實(shí)現(xiàn)起來也不難,主要頭痛的是在前后無縫與按鈕定位之間的配合問題,不過還好現(xiàn)在總算OK了。
    2010-11-11
  • html+JavaScript煙花3D簡單特效(親測可用)

    html+JavaScript煙花3D簡單特效(親測可用)

    網(wǎng)頁煙花特效方便使用,更能給養(yǎng)眼享受,復(fù)制黏貼就能使用,快來試試吧。這篇文章主要介紹了html+JavaScript煙花3D特效(親測可用),需要的朋友可以參考下
    2023-01-01
  • 花瓣漫天飛舞js特效,簡單浪漫

    花瓣漫天飛舞js特效,簡單浪漫

    現(xiàn)代社會結(jié)婚、走紅毯等很多時候會撒花瓣,滿天花瓣和賞煙花一樣,人們都覺得那一瞬間好美麗好浪漫。就像曇花一現(xiàn),美好的事物總是很短暫,提醒人們?nèi)フ湎А_@篇文章主要介紹了花瓣漫天飛舞js特效,簡單浪漫,程序猿們可以跟女朋友一起欣賞
    2023-01-01
  • javascript實(shí)現(xiàn)div的拖動并調(diào)整大小類似qq空間個性編輯模塊

    javascript實(shí)現(xiàn)div的拖動并調(diào)整大小類似qq空間個性編輯模塊

    qq空間的個性編輯模塊可以隨意的拖動頁面上的元素并且調(diào)動大小實(shí)現(xiàn)動態(tài)布局;這種效果的確很酷,那么我們也來實(shí)現(xiàn)一個吧
    2012-12-12
  • 隨機(jī)顯示個性簽名的js代碼(兼容ie,firefox)

    隨機(jī)顯示個性簽名的js代碼(兼容ie,firefox)

    隨機(jī)顯示個性簽名的js代碼,主要是利用隨機(jī)數(shù)。需要的朋友可以參考下。
    2011-04-04
  • 網(wǎng)頁計(jì)算器 一個JS計(jì)算器

    網(wǎng)頁計(jì)算器 一個JS計(jì)算器

    一個挺小的JavaScript網(wǎng)頁計(jì)算器,界面美化的我想還是不錯的,畢竟在沒有使用任何圖片修飾的情況下,很好看,而且功能挺實(shí)用,可以完成基本的數(shù)學(xué)算數(shù)運(yùn)算
    2013-09-09

最新評論