大学时写的一些小程序-1 (js写的小钟表 很难看)
2009-12-11 15:59
281 查看
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body >
<script language="javascript">
var nodecot=60
var check=0;
var num=30;
var ClockId;
var cotClo=1;
var direct=1;
var cloLen=200;
var Timer=document.createElement("<div id='timer'></div>");
document.body.insertBefore(Timer);
Timer.style.position="absolute";
Timer.style.left=420;
Timer.style.top=370;
var RadioC = document.createElement("<INPUT TYPE='radio' NAME='RadioCentre' VALUE='First Choice' checked='checked'>");
document.body.insertBefore(RadioC);
RadioC .style.position="absolute";
RadioC .style.left=450;
RadioC .style.top =350;
var buttonCentre= document.createElement("<INPUT TYPE='button' id='buttonCentre1' VALUE='Start Clock' onclick='return startClock()'>");
document.body.insertBefore(buttonCentre);
buttonCentre.style.position="absolute";
buttonCentre.style.left=300;
buttonCentre.style.top =600;
var buttonCentre= document.createElement("<INPUT TYPE='button' id='buttonCentre2' VALUE='Stop Clock' onclick='return stopClock()'>");
document.body.insertBefore(buttonCentre);
buttonCentre.style.position="absolute";
buttonCentre.style.left=500;
buttonCentre.style.top =600;
for(var i=0;i<nodecot;i++)
{
var newRadioButton = document.createElement("<INPUT TYPE='radio' NAME='RADIOTEST' VALUE='First Choice'>")
document.body.insertBefore(newRadioButton);
newRadioButton.style.position ="absolute";
}
for(var i=0;i<nodecot;i++)
{
var Radio = document.getElementsByName("RADIOTEST")
Radio[i].style.left=cloLen*Math.sin((i*(360/nodecot)/180)*Math.PI)+450;
Radio[i].style.top =cloLen*Math.cos((i*(360/nodecot)/180)*Math.PI)+350;
}
ClockId=window.setInterval(changeCheck,1000);
function changeCheck(){
var dateTime=new Date();
var sec =dateTime.getSeconds();
var nowp;
document.getElementById("timer").innerHTML=dateTime.getHours()+"时"+dateTime.getMinutes()+"分"+sec+"秒";
if(sec>=0&&sec<=30) nowp=30-sec;
if(sec>30&&sec<60) nowp=90-sec;
document.getElementsByName("RADIOTEST")[nowp].checked='checked';
document.getElementsByName("RADIOTEST")[nowp].style.backgroundColor='red';
if(nowp>59)nowp=0
document.getElementsByName("RADIOTEST")[nowp+1].style.backgroundColor='beige';
//document.getElementById("div").innerHTML=j+" ";
}
document.onmousedown=MouseDown;
document.onmouseup=MouseDown3;
function MouseDown(){
document.onmousemove=MouseDown2;
document.onmouseup=MouseDown3;
}
function MouseDown2(){
document.getElementById("div2").innerHTML="X:"+event.x+" Y:"+event.y;
//document.getElementById("div3").innerHTML=Math.abs(parseInt(document.getElementById("RadioCentre").style.left)-event.x);
var widlen=Math.abs(parseInt(document.getElementById("RadioCentre").style.left)-event.x);
var heilen=Math.abs(parseInt(document.getElementById("RadioCentre").style.top)-event.y);
//document.getElementById("div3").innerHTML=Math.sqrt(widlen*widlen+heilen*heilen);
if(widlen<100&&heilen<100)
//if(Math.sqrt(widlen*widlen+heilen*heilen)<100)
{
document.getElementById("RadioCentre").style.left=event.x;
document.getElementById("RadioCentre").style.top=event.y;
for(var i=0;i<nodecot;i++)
{
var Radio = document.getElementsByName("RADIOTEST")
Radio[i].style.left=cloLen*Math.sin((i*(360/nodecot)/180)*Math.PI)+event.x;
Radio[i].style.top =cloLen*Math.cos((i*(360/nodecot)/180)*Math.PI)+event.y;
}
document.getElementById("timer").style.left=event.x-30;
document.getElementById("timer").style.top=event.y+20;
}
var widlenBu=Math.abs(parseInt(document.getElementById("buttonCentre1").style.left)-event.x);
var heilenBu=Math.abs(parseInt(document.getElementById("buttonCentre1").style.top)-event.y);
//document.getElementById("div3").innerHTML=Math.abs(parseInt(document.getElementById("buttonCentre1").style.left)-event.x)+"___"+Math.abs(parseInt(document.getElementById("buttonCentre1").style.top)-event.y);;
if(widlenBu<120&&heilenBu<30)
{
document.getElementById("buttonCentre1").style.left=event.x;
document.getElementById("buttonCentre1").style.top=event.y;
}
var widlenBu2=Math.abs(parseInt(document.getElementById("buttonCentre2").style.left)-event.x);
var heilenBu2=Math.abs(parseInt(document.getElementById("buttonCentre2").style.top)-event.y);
if(widlenBu2<120&&heilenBu2<30)
{
document.getElementById("buttonCentre2").style.left=event.x;
document.getElementById("buttonCentre2").style.top=event.y;
}
if(Math.abs(widlenBu-widlenBu2)<10&&Math.abs(heilenBu-heilenBu2)<10)
{
document.getElementById("buttonCentre1").style.left=100;
document.getElementById("buttonCentre1").style.top=600;
document.getElementById("buttonCentre2").style.left=300;
document.getElementById("buttonCentre2").style.top=600;
}
return false;
}
function MouseDown3(){
//document.getElementById("div2").innerHTML="";
document.onmousemove = null;
}
function stopClock(){
if(cotClo<0)return false;
else{ window.clearInterval(ClockId);cotClo--;}
}
function startClock(){
if(cotClo>0) return false;
else {
ClockId=window.setInterval(changeCheck,1000);cotClo++;
}
}
</script>
<div id="div"></div>
<div id="div2"></div>
<div id="div3"></div>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body >
<script language="javascript">
var nodecot=60
var check=0;
var num=30;
var ClockId;
var cotClo=1;
var direct=1;
var cloLen=200;
var Timer=document.createElement("<div id='timer'></div>");
document.body.insertBefore(Timer);
Timer.style.position="absolute";
Timer.style.left=420;
Timer.style.top=370;
var RadioC = document.createElement("<INPUT TYPE='radio' NAME='RadioCentre' VALUE='First Choice' checked='checked'>");
document.body.insertBefore(RadioC);
RadioC .style.position="absolute";
RadioC .style.left=450;
RadioC .style.top =350;
var buttonCentre= document.createElement("<INPUT TYPE='button' id='buttonCentre1' VALUE='Start Clock' onclick='return startClock()'>");
document.body.insertBefore(buttonCentre);
buttonCentre.style.position="absolute";
buttonCentre.style.left=300;
buttonCentre.style.top =600;
var buttonCentre= document.createElement("<INPUT TYPE='button' id='buttonCentre2' VALUE='Stop Clock' onclick='return stopClock()'>");
document.body.insertBefore(buttonCentre);
buttonCentre.style.position="absolute";
buttonCentre.style.left=500;
buttonCentre.style.top =600;
for(var i=0;i<nodecot;i++)
{
var newRadioButton = document.createElement("<INPUT TYPE='radio' NAME='RADIOTEST' VALUE='First Choice'>")
document.body.insertBefore(newRadioButton);
newRadioButton.style.position ="absolute";
}
for(var i=0;i<nodecot;i++)
{
var Radio = document.getElementsByName("RADIOTEST")
Radio[i].style.left=cloLen*Math.sin((i*(360/nodecot)/180)*Math.PI)+450;
Radio[i].style.top =cloLen*Math.cos((i*(360/nodecot)/180)*Math.PI)+350;
}
ClockId=window.setInterval(changeCheck,1000);
function changeCheck(){
var dateTime=new Date();
var sec =dateTime.getSeconds();
var nowp;
document.getElementById("timer").innerHTML=dateTime.getHours()+"时"+dateTime.getMinutes()+"分"+sec+"秒";
if(sec>=0&&sec<=30) nowp=30-sec;
if(sec>30&&sec<60) nowp=90-sec;
document.getElementsByName("RADIOTEST")[nowp].checked='checked';
document.getElementsByName("RADIOTEST")[nowp].style.backgroundColor='red';
if(nowp>59)nowp=0
document.getElementsByName("RADIOTEST")[nowp+1].style.backgroundColor='beige';
//document.getElementById("div").innerHTML=j+" ";
}
document.onmousedown=MouseDown;
document.onmouseup=MouseDown3;
function MouseDown(){
document.onmousemove=MouseDown2;
document.onmouseup=MouseDown3;
}
function MouseDown2(){
document.getElementById("div2").innerHTML="X:"+event.x+" Y:"+event.y;
//document.getElementById("div3").innerHTML=Math.abs(parseInt(document.getElementById("RadioCentre").style.left)-event.x);
var widlen=Math.abs(parseInt(document.getElementById("RadioCentre").style.left)-event.x);
var heilen=Math.abs(parseInt(document.getElementById("RadioCentre").style.top)-event.y);
//document.getElementById("div3").innerHTML=Math.sqrt(widlen*widlen+heilen*heilen);
if(widlen<100&&heilen<100)
//if(Math.sqrt(widlen*widlen+heilen*heilen)<100)
{
document.getElementById("RadioCentre").style.left=event.x;
document.getElementById("RadioCentre").style.top=event.y;
for(var i=0;i<nodecot;i++)
{
var Radio = document.getElementsByName("RADIOTEST")
Radio[i].style.left=cloLen*Math.sin((i*(360/nodecot)/180)*Math.PI)+event.x;
Radio[i].style.top =cloLen*Math.cos((i*(360/nodecot)/180)*Math.PI)+event.y;
}
document.getElementById("timer").style.left=event.x-30;
document.getElementById("timer").style.top=event.y+20;
}
var widlenBu=Math.abs(parseInt(document.getElementById("buttonCentre1").style.left)-event.x);
var heilenBu=Math.abs(parseInt(document.getElementById("buttonCentre1").style.top)-event.y);
//document.getElementById("div3").innerHTML=Math.abs(parseInt(document.getElementById("buttonCentre1").style.left)-event.x)+"___"+Math.abs(parseInt(document.getElementById("buttonCentre1").style.top)-event.y);;
if(widlenBu<120&&heilenBu<30)
{
document.getElementById("buttonCentre1").style.left=event.x;
document.getElementById("buttonCentre1").style.top=event.y;
}
var widlenBu2=Math.abs(parseInt(document.getElementById("buttonCentre2").style.left)-event.x);
var heilenBu2=Math.abs(parseInt(document.getElementById("buttonCentre2").style.top)-event.y);
if(widlenBu2<120&&heilenBu2<30)
{
document.getElementById("buttonCentre2").style.left=event.x;
document.getElementById("buttonCentre2").style.top=event.y;
}
if(Math.abs(widlenBu-widlenBu2)<10&&Math.abs(heilenBu-heilenBu2)<10)
{
document.getElementById("buttonCentre1").style.left=100;
document.getElementById("buttonCentre1").style.top=600;
document.getElementById("buttonCentre2").style.left=300;
document.getElementById("buttonCentre2").style.top=600;
}
return false;
}
function MouseDown3(){
//document.getElementById("div2").innerHTML="";
document.onmousemove = null;
}
function stopClock(){
if(cotClo<0)return false;
else{ window.clearInterval(ClockId);cotClo--;}
}
function startClock(){
if(cotClo>0) return false;
else {
ClockId=window.setInterval(changeCheck,1000);cotClo++;
}
}
</script>
<div id="div"></div>
<div id="div2"></div>
<div id="div3"></div>
</body>
</html>
相关文章推荐
- 大学时写的一些小程序-2(js的小型文件控制程序)
- 大学时写的一些小程序-3(js的小型文件分析程序)
- 大学时写的一些小程序-7(颜色生成)
- 大学时写的一些小程序-8(c桌面时钟)
- 一些有用的js程序
- 实现js与Qt程序的交互的一些方法
- js程序 下拉框功能,当选择大学下拉框时,隐藏下拉框,将其对应的值,展示到span标签中
- 充分发挥Node.js程序性能的一些方法介绍
- 大学时写的一些小程序-4(c鼠标)
- 大学时写的一些小程序-5(c写的圆碰撞程序)
- 大学时写的一些小程序-6(vc图片处理)
- 充分发挥Node.js程序性能的一些方法介绍
- JS高级程序设置笔记(四)
- 【node.js】本地模式安装express:'express' 不是内部或外部命令,也不是可运行的程序或批处理文件。
- 【js基础】JS事件处理程序
- IE、火狐和谷歌关于一些JS的差异
- Angular.js 的一些学习资源
- js 中的 一些简单算法(二)之 双层循环—冒泡排序
- 收集一些js学习网站
- vue以及js的一些坑或常用技巧