javascript计算星座属相(十二生肖属相)示例代码_javascript技巧

复制代码 代码如下:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function signs() {
var start = 1901, birthyear = document.zodiac.year.value, date=document.zodiac.date.value, month=document.zodiac.month.selectedIndex;

with (document.zodiac.sign){

if (month == 1 && date >=20 || month == 2 && date <=18) {value = "水瓶座";}
if (month == 1 && date > 31) {value = "Huh?";}
if (month == 2 && date >=19 || month == 3 && date <=20) {value = "双鱼座";}
if (month == 2 && date > 29) {value = "Say what?";}
if (month == 3 && date >=21 || month == 4 && date <=19) {value = "白羊座";}
if (month == 3 && date > 31) {value = "OK.  Whatever.";}
if (month == 4 && date >=20 || month == 5 && date <=20) {value = "金牛座";}
if (month == 4 && date > 30) {value = "I'm soooo sorry!";}
if (month == 5 && date >=21 || month == 6 && date <=21) {value = "双子座";}
if (month == 5 && date > 31) {value = "Umm ... no.";}
if (month == 6 && date >=22 || month == 7 && date <=22) {value = "巨蟹座";}
if (month == 6 && date > 30) {value = "Sorry.";}
if (month == 7 && date >=23 || month == 8 && date <=22) {value = "狮子座";}
if (month == 7 && date > 31) {value = "Excuse me?";}
if (month == 8 && date >=23 || month == 9 && date <=22) {value = "室女座";}
if (month == 8 && date > 31) {value = "Yeah. Right.";}
if (month == 9 && date >=23 || month == 10 && date <=22) {value = "天秤座";}
if (month == 9 && date > 30) {value = "Try Again.";}
if (month == 10 && date >=23 || month == 11 && date <=21) {value = "天蝎座";}
if (month == 10 && date > 31) {value = "Forget it!";}
if (month == 11 && date >=22 || month == 12 && date <=21) {value = "人马座";}
if (month == 11 && date > 30) {value = "Invalid Date";}
if (month == 12 && date >=22 || month == 1 && date <=19) {value = "摩羯座";}
if (month == 12 && date > 31) {value = "No way!";}
}
x = (start - birthyear) % 12
with (document.zodiac.csign){
if (x == 1 || x == -11) {value = "老鼠";}
if (x == 0) {value = "牛";}
if (x == 11 || x == -1) {value = "老虎";}
if (x == 10 || x == -2) {value = "兔子";}
if (x == 9 || x == -3)  {value = "龙";}
if (x == 8 || x == -4)  {value ="蛇";}
if (x == 7 || x == -5)  {value = "马";}
if (x == 6 || x == -6)  {value = "羊";}
if (x == 5 || x == -7)  {value = "猴子";}
if (x == 4 || x == -8)  {value = "鸡";}
if (x == 3 || x == -9)  {value = "狗";}
if (x == 2 || x == -10)  {value = "猪";} 

}
}
//  End -->
</script>
<form name="zodiac">
<center>
<table bgcolor="#eeaa00" border="2" bordercolor="#000000" rules="none" cellspacing="0" cellpadding="4">
    <tr><td><b><i>出生年份</i></b></td>
    <td><div align="right"><input type="text" size="10" name="year" value="出生年份" onClick=value=""></div></td>
    <td><!--This empty field is just for appearance--></td>
    <tr><td><b><i>出生月份</i></b></td>
    <td><div align="right">
<select name="month">
<option value="x">请选择一个月份</option>
<option value="1">一月</option><option value="2">二月</option><option value="3">三月</option>
<option value="4">四月</option><option value="5">五月</option><option value="6">六月</option>
<option value="7">七月</option><option value="8">八月</option><option value="9">九月</option>
<option value="10">十月</option><option value="11">十一月</option>
<option value="12">十二月</option></select></div></td>
    <td><!--This empty field is just for appearance--></td></tr>
    <tr><td><b><i>天</i></b></td>
    <td><div align="right"><input type="text" name="date" value="天" size="3" onClick=value=""></td>
    <td><input type="button" value="计算一下" onClick="signs()"></div></td></tr>
    <tr><td><b><i>星座:</i></b></td>
    <td><div align="right"><input type="text" name="sign" size="12" value="" align="right"></div></td></tr>
    <td><!--This empty field is just for appearance--></td></tr>
    <tr><td><b><i>属相:</i></b></td>
    <td><div align="right"><input type="text" name="csign" size="12"></div></td>
    <td><!--This empty field is just for appearance--></td></tr>

</table>
</center>
</form>

时间: 2024-07-28 13:19:08

javascript计算星座属相(十二生肖属相)示例代码_javascript技巧的相关文章

JavaScript 计算图片加载数量的代码_javascript技巧

通过JavaScript 来计算当前图片加载的张数. 原理: 先定义一个图片的数组,然后通过image的onload事件来计算,注意,onload在ie和火狐有所不同. 最后需要一个进度条与之结合即可. 这个脚本在做游戏的地方用得比较多. 演示: 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1

Javascript遍历table中的元素示例代码_javascript技巧

例如: <table id=tb> <tr><th> </th><th> </th><th> </th><th> </th></tr> <tr><td> </td><td> </td><td> </td><td> </td></tr> <tr>&

通过javascript获取iframe里的值示例代码_javascript技巧

复制代码 代码如下: <script type="text/javascript" language="javascript"> function CCCC(){ var File_NAME=""; var count=0; if(document.frames("myFrame").document.all.length){ for(var i=0;i<document.all.length;i++){ i

javascript:json数据的页面绑定示例代码_javascript技巧

web开发中,如果需要将"服务端返回的json对象"绑定到"现有页面上的dom元素",传统赋值的方式太繁琐,写起来也很累(特别是json对象很大时),于是想出了下面的偷懒方法,不过有二个前提: 1.元素的id要与json对象中的属性命名一致2.json对象中的属性名,最好不要重复 复制代码 代码如下: <!doctype html><html><head><title>json对象遍历演示</title>&

用javascript替换URL中的参数值示例代码_javascript技巧

今天遇到一个需要用javascript将url中的某些参数替换的需求,想起了不久前从网上淘到了一个parseUrl函数,正好可以借此实现,代码整理如下: 复制代码 代码如下: //分析url function parseURL(url) {     var a = document.createElement('a');     a.href = url;     return {         source: url,         protocol: a.protocol.replace

javascript 表格内容排序 简单操作示例代码_javascript技巧

复制代码 代码如下: <div id="html"></div> <script> var listInfos = new Array(); listInfos[0] = new Array(); listInfos[0][0] = {'name':'推荐页1','DayCount':666,'AvgTime':29872,'ErrCount':180663,'ErrorRate':'2873%','DaySystemErrorCount':0,'D

javascript中数组中求最大值示例代码_javascript技巧

复制代码 代码如下: <html> <head> <title>数组的最大值的获取</title> <script> //定义数组 var arr = [1,4,3,9,5,0,-1,7,22]; //最大值的下标,先假定为第一个元素的下标 var index = 0; for(var x = 0; x < arr.length; x++){ if(arr[index] < arr[x]){ index = x; } } docume

Javascript设置对象的ReadOnly属性(示例代码)_javascript技巧

在JS中ReadOnly属性比较奇怪,直接创建一个对象,给该对象赋值readonly属性不能够向HTML中一样使用下面的方式: 复制代码 代码如下: var x=document.createElement("input");x.type="text";x.value="ttttt";x.id="xy";x.readonly="readonly"; 这样创建的对象并不是只读的.正确的写法是: 复制代码 代码

分享javascript计算时间差的示例代码_javascript技巧

在实际应用中,需要计算两个时间点之间的差距,一般来说都是计算当前时间和一个指定时间点之间的差距,并且有时候需要精确到天.小时.分钟和秒,下面就简单介绍一下如何实现此效果. 效果图: 距离新年: 代码如下: <html> <head> <title>javascript计算时间差</title> <style type="text/css"> #thenceThen { font-size:2em; } </style&g

javaScript 计算两个日期的天数相差(示例代码)_javascript技巧

一:计算两个日期相差的天数 比如:   str1  =  "2002-01-20"   str2  =  "2002-10-11"  怎样用javaScript计算出str1与str2之间相差的天数?  复制代码 代码如下: <html>  <head>  <meta  http-equiv="Content-Type"  content="text/html;  charset=gb2312"&