平常上qq空间的爱侣一定对qq空间的秉性编辑模块印象深刻,能够随意的拖动页面上的成分並且调动大小完结动态布局,当然作者老是上csdn博客也会在右下角看见叁个谍报窗口,这种效果确实很酷,那么大家也来促成一个吧.

图片 1

时常使用google的恋人一定对google秀丽的日历控件日思夜想吧,那大家也来兑现贰个,即便功能和意义不及,但首要的是促成的进度.
上边是要促成的html结构:
<div id=”a”><div id=”head”><span
id=”yface”>年:<select
id=”year”></select></span><span
id=”mface”>月:<select
id=”month”></select></span></div><div
id=”biaoti”></div><div
id=”body”></div></div>
先说一下日历查询的算法:
w=y+parseInt(y/4)+parseInt(c/4)-2*c+parseInt(26*(m+1)/10)+d-1 ;
上面是事无巨细的证实经过,有意思味的能够去看下: 

以下是实现的javascript代码:

落到实处步骤:
1.第一是动态创制二个看似那样的html结构:

丰裕数据 :
图片 2

复制代码 代码如下:

复制代码 代码如下:

数量显示:
图片 3

sx.activex.calender={
bind:function(target){
var a=document.createElement(“div”);
var head=document.createElement(“div”);
var biaoti=document.createElement(“div”);
var select=document.createElement(“select”);
var yface=document.createElement(“span”);
var mface=document.createElement(“span”);
var body=document.createElement(“div”);
var select1=document.createElement(“select”);
yface.appendChild(select);
mface.appendChild(select1);
head.appendChild(yface);
head.appendChild(mface);
a.appendChild(head);
a.appendChild(biaoti);
a.appendChild(body);
yface.insertBefore(document.createTextNode(“年 “),yface.firstChild)
mface.insertBefore(document.createTextNode(“月 “),mface.firstChild)
a.style.position=”absolute”;
biaoti.style.height=”10%”;
for(var i=0;i<7;i++){
var can=document.createElement(“span”)
can.style.width=”14%”;
can.style.height=”100%”;
can.style.textAlign=”center”;
biaoti.appendChild(can);
}
biaoti.all[0].innerText=”日”
biaoti.all[1].innerText=”一”
biaoti.all[2].innerText=”二”
biaoti.all[3].innerText=”三”
biaoti.all[4].innerText=”四”
biaoti.all[5].innerText=”五”
biaoti.all[6].innerText=”六”
head.style.height=”20%”;
a.style.position=”absolute”;
a.style.height=”200px”;
a.style.width=”302px”;
a.style.border=”1px red solid”;
yface.style.width=”50%”;
yface.style.padding=”5px”;
yface.style.height=”100%”;
select.style.width=”80%”;
for(var i=1960;i<2010;i++){
var option=document.createElement(“option”);
option.text=i;
select.add(option);
}
mface.style.width=”50%”;
mface.style.padding=”5px”;
mface.style.height=”100%”;
select1.style.width=”80%”;
for(var i=1;i<=12;i++){
var option=document.createElement(“option”);
option.text=i;
select1.add(option);
}
body.style.height=”70%”;
for(var i=0;i<42;i++){
var span=document.createElement(“span”);
span.style.width=”14%”;
span.style.height=”16%”;
span.style.textAlign=”center”;
span.onmouseover=function(){
this.style.cursor=”hand”;
this.tempcolor=this.style.backgroundColor;
this.style.backgroundColor=”lightblue”;
}
span.onmouseout=function(){
this.style.backgroundColor=this.tempcolor;
}
span.onclick=function(){
target.value=select.options[select.selectedIndex].text+”年”+select1.options[select1.selectedIndex].text+”月”+this.innerText+”日”;
a.parentNode.removeChild(a);
}
body.appendChild(span);
}
select.onchange=function(){
for(var o in body.all){
body.all[o].innerText=””;
if(o.toString()!=”length”)
body.all[o].style.backgroundColor=””;
}
var year1=this.options[this.selectedIndex].text;
var month1=select1.options[select1.selectedIndex].text;
var y=parseInt(year1.substr(2,2)-0);
var c=parseInt(year1.substr(0,2));;
var m=parseInt(month1);;
m=m>=3?m:(y=y-1,m+12);
var d=1;
var w=y+parseInt(y/4)+parseInt(c/4)-2*c+parseInt(26*(m+1)/10)+d-1 ;
if(w<0) w=w+700;
w=w%7;
switch(parseInt(month1)){
case 2:
if(parseInt(year1)%4==0)
var r=29;
else
var r=28;
var day=w;
for(var d=1;d<=r;d++){
body.all[day++].innerText=d;
if(parseInt(year1)==(new Date()).getYear() && parseInt(month1)==(new
Date()).getMonth()+1 && d==(new Date()).getDate())
body.all[day-1].style.backgroundColor=”red”;
body.all[41].innerText=”关闭”;
}
break;
default:

<div style=”height:200px;width:200px;overflow:hidden” id=”a”>
<div id=”head” style=”background-color:blue;height:5%”>
<span id=”move” style=”width:90%;height:100%”></span>
<span id=”close”
style=”overflow:hidden;white-space:nowrap;background-color:red”>关闭</span>
</div>
<div id=”body” style=”width:100%;height:90%”></div>
</div>

ClassModel.js源码 ::

if(parseInt(month1)==1 || parseInt(month1)==3 || parseInt(month1)==5 ||
parseInt(month1)==7 || parseInt(month1)==8 || parseInt(month1)==10 ||
parseInt(month1)==12)
var r=31;
else
var r=30;
var day=w;
for(var d=1;d<=r;d++){
body.all[day++].innerText=d;
if(parseInt(year1)==(new Date()).getYear() && parseInt(month1)==(new
Date()).getMonth()+1 && d==(new Date()).getDate())
body.all[day-1].style.backgroundColor=”red”;
body.all[41].innerText=”关闭”;
}
break;

2.id为body的为你要放置内容的div容器,move是可活动的span,close是关门那些窗口(正确说是层).
3.然后将事件绑定到那个目的上.具体看一下代码.

复制代码 代码如下:

}

复制代码 代码如下:

ClassModel =
{
    create : function()
     {
        return function()
        {
            this.construct.apply(this, arguments);
        }
     }
}
Extend = function(desc, src)
    {
        for(var c in src)
        {
            desc[c] = src[c];
        }
        return desc;
    }
Object.prototype.extend = function(src)
    {
        return Extend.apply(this, [this, src]);
    }

}
select1.onchange=function(){
for(var o in body.all){
body.all[o].innerText=””;
if(o.toString()!=”length”)
body.all[o].style.backgroundColor=””;
}
var month1=this.options[this.selectedIndex].text;
var year1=select.options[select.selectedIndex].text;
var y=parseInt(year1.substr(2,2)-0);
var c=parseInt(year1.substr(0,2));
var m=parseInt(month1);
m=m>=3?m:(y=y-1,m+12);
var d=1;
var w=y+parseInt(y/4)+parseInt(c/4)-2*c+parseInt(26*(m+1)/10)+d-1 ;
if(w<0) w=w+700;
w=w%7;
switch(parseInt(month1)){
case 2:
if(parseInt(year1)%4==0)
var r=29;
else
var r=28;
var day=w;
for(var d=1;d<=r;d++){
body.all[day++].innerText=d;
if(parseInt(year1)==(new Date()).getYear() && parseInt(month1)==(new
Date()).getMonth()+1 && d==(new Date()).getDate())
body.all[day-1].style.backgroundColor=”red”;
body.all[41].innerText=”关闭”;
}
break;
default:

sx.activex.windowex={
init:function(step,t,html){
var a=document.createElement(“div”);
var head=document.createElement(“div”);
var move=document.createElement(“span”);
var close=document.createElement(“span”);
close.innerText=”关闭”;
var body=document.createElement(“div”);
head.appendChild(move);
head.appendChild(close);
a.appendChild(head);
a.appendChild(body);
a.style.height=”200px”;
a.style.width=”200px”;
a.style.overflow=”hidden”;
a.style.border=”1px red solid”;
head.style.backgroundColor=”blue”;
head.style.height=”5%”;
move.style.width=”90%”;
move.style.height=”100%”;
close.style.height=”100%”;
close.style.overflow=”hidden”;
close.style.whiteSpace=”nowrap”;
close.style.backgroundColor=”yellow”;
body.style.height=”93%”;
body.style.width=”100%”;
body.style.overflow=”auto”;
a.style.position=”absolute”;
close.style.position=”absolute”;
close.style.cursor=”hand”;
close.style.top=0+”px”;
close.style.right=0+”px”;
close.onclick=function(){
window.event.cancelBubble=true;
var q=a.offsetHeight;
var h=window.setInterval(function(){
if(Math.abs(q)>=0){
a.style.height=q+”px”;
q=q-step;
if(Math.abs(q)<step){
//e.style.height=q+”px”;
window.clearInterval(h);
//window.setTimeout(function(){
//alert(this==window);
close.style.cursor=”normal”;
a.parentNode.removeChild(a);
//a.style.lineHeight=”0px”;
//},10);
}
}else{
window.clearInterval(h);
//a.style.display=”none”;
}
},t);
}
move.onmousedown=function(){
this.move=1;
this.x=window.event.offsetX;
//alert(this.x);
this.y=window.event.offsetY;
this.setCapture();
}
move.onmousemove=function(){
this.style.cursor=”move”;
if(window.event.clientX<=0 || window.event.clientY<=0 ||
window.event.clientX>=document.body.clientWidth ||
window.event.clientY>=document.body.clientHeight){return false;}
if(this.move==1){

addData.js源码::

if(parseInt(month1)==1 || parseInt(month1)==3 || parseInt(month1)==5 ||
parseInt(month1)==7 || parseInt(month1)==8 || parseInt(month1)==10 ||
parseInt(month1)==12)
var r=31;
else
var r=30;
var day=w;
for(var d=1;d<=r;d++){
body.all[day++].innerText=d;
if(parseInt(year1)==(new Date()).getYear() && parseInt(month1)==(new
Date()).getMonth()+1 && d==(new Date()).getDate())
body.all[day-1].style.backgroundColor=”red”;
body.all[41].innerText=”关闭”;
}
break;

this.parentNode.parentNode.style.left=window.event.clientX-this.x+”px”;
this.parentNode.parentNode.style.top=window.event.clientY-this.y+”px”;
this.setCapture();
}
}
move.onmouseup=function(){
if(this.move==1){
this.move=0;
//this.style.cursor=”normal”;
this.releaseCapture();
}
}
a.onmousemove=function(){
if(this.move==1){
if(window.event.clientX-this.offsetLeft<2 ||
window.event.clientY-this.offsetTop<2) return false;
this.style.width=window.event.clientX-this.offsetLeft+”px”;
this.style.height=window.event.clientY-this.offsetTop+”px”;
close.style.right=”0px”;
this.setCapture();
}
else{
if(window.event.offsetX-this.offsetWidth>-6 &&
window.event.offsetY-this.offsetHeight>-6)
this.style.cursor=”nw-resize”;
else
this.style.cursor=”default”;
}
}
a.onmouseup=function(){
if(this.move==1){
this.move=0;
this.releaseCapture();
}
}
a.onmousedown=function(){
if(this.style.cursor==”nw-resize”){
this.move=1;
this.setCapture();
}
}
body.innerHTML=html;
return a;
}

复制代码 代码如下:

}

代码也不复杂,主假使怎么着onmousedown,onmousemove,onmouseup的编写.作者调动大小的原理当的您鼠标移动到层的右下角时,鼠标指针改换,那时按下鼠标而且一举手一投足时,会将近期层setcapture,移动鼠标层会随鼠标的职分而调治大小,撒手鼠标releasecapture.

var insert = ClassModel.create();
var doc = new ActiveXObject(“Msxml2.DOMDocument.3.0”);
doc.load(“books.xml”);
var books;
insert.prototype =
{
construct : function(config)
{
this.id = config.id;
this.name = config.name;
this.author = config.author;
this.price = config.price;
this.publisher = config.publisher;
this.count = config.count;
this.insertData();
},
insertData : function()
{

}
var date=new Date();

函数的参数step是你按下关闭时老是时间间隔移动的步数,t是时间距离,html是你要插入到body层里的html代码.
马上间交给三个调用例子:

var book = doc.createElement(“book”);

for(var s1=0;s1<select.options.length;s1++){
if(parseInt(select.options[s1].text)==parseInt(date.getYear())){
select.options[s1].selected=true;
break;
}
}
for(var s2=0;s2<select1.options.length;s2++){
if(parseInt(select1.options[s2].text)==parseInt(date.getMonth())+1){
select1.options[s2].selected=true;
break;
}
}
select.onchange();
for(var i in body.all){
if(body.all[i].innerText==date.getDate()){
body.all[i].style.backgroundColor=”red”;
}
}
target.onfocus=function(){
document.body.appendChild(a);
a.style.left=target.offsetLeft+”px”;;
a.style.top=target.offsetTop+target.offsetHeight+”px”;
}
target.onblur=function(){
if(a && window.event.clientY>a.offsetTop &&
window.event.clientY<a.offsetTop+a.offsetHeight &&
window.event.clientX>a.offsetLeft &&
window.event.clientX<a.offsetLeft+a.offsetWidth)
return;
if(!a) return;
a.parentNode.removeChild(a);
}
body.all[41].innerText=”关闭”;
body.all[41].onclick=function(){
this.style.backgroundColor=””;
a.parentNode.removeChild(a);

复制代码 代码如下:

book.setAttribute(“id”, this.id);
var name = doc.createElement(“name”);
var nameValue = doc.createTextNode(this.name);
name.appendChild(nameValue);
book.appendChild(name);
var author = doc.createElement(“author”);
var authorValue = doc.createTextNode(this.author);
author.appendChild(authorValue);
book.appendChild(author);
var price = doc.createElement(“price”);
var priceValue = doc.createTextNode(this.price);
price.appendChild(priceValue);
book.appendChild(price);

}
}
}

<html>
<head>
<title>Untitled Document</title>
</head>
<body>

var count = doc.createElement(“count”);
var countValue = doc.createTextNode(this.count);
count.appendChild(countValue);
book.appendChild(count);
var publisher = doc.createElement(“publisher”);
var publisherValue = doc.createTextNode(this.publisher);
publisher.appendChild(publisherValue);
book.appendChild(publisher);

入口参数是要绑定的html对象,这里一般是text input.
下边是调用代码:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<script src=”kongjian.js”></script>
<input type=”text” id=”a”>
<script>
sx.activex.calender.bind(document.getElementById(“a”));
</script>
</body>
</html>
大概就那样,代码比较冗长,不是很好,假诺哪位朋友有越来越好的艺术,请与自己多么交换啊.

<mce:script src=”kongjian.js”
mce_src=”kongjian.js”></mce:script>

if(doc.documentElement == null)
{

.
下边是要实…