html输入年份求属相,在窗体应用程序中怎么输出年份然后显示生肖,求代

html输入年份求属相,在窗体应用程序中怎么输出年份然后显示生肖,求代,第1张

提起html输入年份属相,大家都知道,有人问输入年份,判断该年的生肖,另外,还有人想问怎么用年份推算生肖?求方法,你知道这是怎么回事?其实编写程序,输入一个年份,判断该年属相.(提示switch-…,下面就一起来看看在窗体应用程序中怎么输出年份然后显示生肖,求代码,希望能够帮助到大家!

html输入年份求属相

这个可以用取模的方式实现。主要思路如下:

dimyearasinteger

dimremasinteger

year=val(inputbox(“请输入年份”))

rem=

selectcaserem

case0

msgbox”猴”

case1

msgbox”鸡”

case2

msgbox”狗”

case3

msgbox”猪”

case4

msgbox”鼠”

case5

msgbox”牛”

编写程序,输入一个年份,判断该年属相.(提示switch-…

case6

msgbox”虎”

case7

msgbox”兔”

case8

msgbox”龙”

case9

msgbox”蛇”

msgbox”马”

msgbox”羊”

endselect

主要代码就是这样了,你在根据要修改完善下就可以了

html输入年份求属相:输入年份,判断该年的生肖

这个答案是:牛

属牛人的性格优点:①勤奋努力,有强烈的进取心;②忠厚老实,务实,责任心强,有耐力;③有正义感,爱打抱不平;

④勤俭持家,稳定。

属牛人的性格弱点:稍微固执已见,缺乏通融;有时钻”牛角尖”主观独断

属牛人的性格详解:从出生时辰对属牛人人生的影响来看,白天出生的安静的夜晚出生的牛更积极、更好斗。与此相仿,夏天出生的冬天出生的牛生活更、更富有。

PHP输入年份查询属相的代码。

PHP通过年份查询属相示例代码如下,具体逻辑体现在代码中。

//判断是否为日期格式,默认时间格式为Y-m-d

function is_date($dateStr,$fmt=”Y-m-d”){

    $dateArr = explode(“-“,$dateStr)

    if(empty($dateArr)){

        return false

    }

    foreach($dateArr as $val){

        if(strlen($val)<2){

            $val=”0″.$val

        }

        $newArr[]=$val

    }

    $dateStr =implode(“-“,$newArr)

    $unixTime=strtotime($dateStr)

    $checkDate= date($fmt,$unixTime)

    if($checkDate==$dateStr)

        return true

    else

        return false//通过出生年月获取属相

function getShuXiang($bithdayDate){

    

    //判断输入日期格式

    if(!is_date($bithdayDate)){

        

        echo “日期输入错误,请检查!”

    }

    //年是鼠年

    $data = array(‘鼠’,’牛’,’虎’,’兔’,’龙’,’蛇’,’马’,’羊’,’猴’,’鸡’,’狗’,’猪’)

    $index = ($bithdayDate-)%12

    return $data[$index]echo “属相:”.getShuXiang(“-05-19”)

//属相:蛇

?>

以上就是与在窗体应用程序中怎么输出年份然后显示生肖,求代码相关内容,是关于输入年份,判断该年的生肖的分享。看完html输入年份求属相后,希望这对大家有所帮助!

<html>

<head>

<title>详细计算你的年龄</title>

<style type="text/css">

<!--

body { font-family: "宋体"font-size: 9ptmargin-top: 0pxmargin-left: 4pxmargin-right: 0px}

A { COLOR: blackFONT-SIZE: 13pxFONT-WEIGHT: 400TEXT-DECORATION: none }

A:hover { COLOR: redFONT-SIZE: 13pxFONT-WEIGHT: 400TEXT-DECORATION: underline }

a:active { font: 9pt "宋体"cursor: handcolor: #FF0033 }

--></style>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">

</head>

<body>

<br>

<center><font color=red face="隶书" size=6>详细计算你的年龄</font></center>

<br>

<center>

<table border=0 bordercolor=blue borderlight=green style="border-collapse: collapse" cellpadding="0" cellspacing="0">

<tr><td align=center><font size=5 color=red face="Arial, Helvetica, sans-serif"><strong>下面框中为脚本显示区</strong></font></td></tr>

<tr><td align=center height=80 width=400>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function run() {

with (document.agecalc) {

dd = parseInt(day.selectedIndex) + 1

mm = parseInt(month.selectedIndex) + 1

yy = year.value

if (yy.length != 4 || isNaN(yy)) {

document.agecalc.timealive.value = "年份数请输入四位."

document.agecalc.year.select()

document.agecalc.year.focus()

return

}

}

days = new Date()

gdate = days.getDate()

gmonth = days.getMonth()

gyear = days.getYear()

if (gyear <2000) gyear += 1900

age = gyear - yy

if ((mm == (gmonth + 1)) &&(dd <= parseInt(gdate))) {

age = age

} else {

if (mm <= (gmonth)) {

age = age

} else {

age = age - 1

}

}

if (age == 0)

age = age

document.agecalc.timealive.value = "你已经" + age+ " 了 . . .\n\n"

if (mm <= (gmonth + 1))

age = age - 1

if ((mm == (gmonth + 1)) &&(dd >parseInt(gdate)))

age = age + 1

var m

var n

if (mm == 12) n = 31 - dd

if (mm == 11) n = 61 - dd

if (mm == 10) n = 92 - dd

if (mm == 9) n = 122 - dd

if (mm == 8) n = 153 - dd

if (mm == 7) n = 184 - dd

if (mm == 6) n = 214 - dd

if (mm == 5) n = 245 - dd

if (mm == 4) n = 275 - dd

if (mm == 3) n = 306 - dd

if (mm == 2) { n = 334 - ddif (leapyear(yy)) n++}

if (mm == 1) { n = 365 - ddif (leapyear(yy)) n++}

if (gmonth == 1) m = 31

if (gmonth == 2) {

m = 59

if (leapyear(gyear)) m++

}

if (gmonth == 3) { m = 90 if (leapyear(gyear)) m++}

if (gmonth == 4) { m = 120if (leapyear(gyear)) m++}

if (gmonth == 5) { m = 151if (leapyear(gyear)) m++}

if (gmonth == 6) { m = 181if (leapyear(gyear)) m++}

if (gmonth == 7) { m = 212if (leapyear(gyear)) m++}

if (gmonth == 8) { m = 243if (leapyear(gyear)) m++}

if (gmonth == 9) { m = 273if (leapyear(gyear)) m++}

if (gmonth == 10) { m = 304if (leapyear(gyear)) m++}

if (gmonth == 11) { m = 334if (leapyear(gyear)) m++}

if (gmonth == 12) { m = 365if (leapyear(gyear)) m++}

months = age * 12

months += 12 - parseInt(mm)

months += gmonth

totdays = (parseInt(age) * 365)

totdays += age / 4

totdays = parseInt(totdays) + gdate + m + n

if (gmonth == 1) p = 31 + gdate

if (gmonth == 2) {

p = 59 + gdate

if (leapyear(gyear)) m = m+1

}

if (gmonth == 3) { p = 90 + gdate if (leapyear(gyear)) p++}

if (gmonth == 4) { p = 120 + gdateif (leapyear(gyear)) p++}

if (gmonth == 5) { p = 151 + gdateif (leapyear(gyear)) p++}

if (gmonth == 6) { p = 181 + gdateif (leapyear(gyear)) p++}

if (gmonth == 7) { p = 212 + gdateif (leapyear(gyear)) p++}

if (gmonth == 8) { p = 243 + gdateif (leapyear(gyear)) p++}

if (gmonth == 9) { p = 273 + gdateif (leapyear(gyear)) p++}

if (gmonth == 10) { p = 304 + gdateif (leapyear(gyear)) p++}

if (gmonth == 11) { p = 334 + gdateif (leapyear(gyear)) p++}

if (gmonth == 12) { p = 365 + gdateif (leapyear(gyear)) p++}

weeks = (age * 365) + n + p

weeks = weeks / 7

etcdays = parseFloat(weeks) - parseInt(weeks)

etcdays = Math.round(etcdays * 7)

weeks = parseInt(weeks)

etcdays += parseInt(age / 4)

if (etcdays >7)

weeks += parseInt(etcdays / 7)

document.agecalc.timealive.value += " 或者 " + weeks + " 个星期\n"

document.agecalc.timealive.value += " 或者 " + months + " 个月\n"

document.agecalc.timealive.value += " 或者 " + totdays + " 天\n"

var time = new Date()

ghour = time.getHours()

gmin = time.getMinutes()

gsec = time.getSeconds()

hour = ((age * 365) + n + p) * 24

hour += (parseInt(age / 4) * 24)

document.agecalc.timealive.value += " 或者 " + hour + " 小时了\n"

var min = (hour * 60) + gmin

document.agecalc.timealive.value += " 或者 " + min + " 分了\n"

sec = (min * 60) + gsec

document.agecalc.timealive.value += " 或者 " + sec + " 秒了"

mm = mm - 1

var r

if (mm == 0) r = 0

if (mm == 1) r = 31

if (mm == 2) { r = 59if (leapyear(gyear)) m++}

if (mm == 3) { r = 90 if (leapyear(gyear)) r++}

if (mm == 4) { r = 120if (leapyear(gyear)) r++}

if (mm == 5) { r = 151if (leapyear(gyear)) r++}

if (mm == 6) { r = 181if (leapyear(gyear)) r++}

if (mm == 7) { r = 212if (leapyear(gyear)) r++}

if (mm == 8) { r = 243if (leapyear(gyear)) r++}

if (mm == 9) { r = 273if (leapyear(gyear)) r++}

if (mm == 10) { r = 304if (leapyear(gyear)) r++}

if (mm == 11) { r = 334if (leapyear(gyear)) r++}

mm = mm + 1

r = parseInt(r) + parseInt(dd)

if ((mm >= (gmonth + 1)) &&(dd >gdate)) {

bday = r - m - gdate

}

else {

if ((leapyear(gyear)) &&((mm >2) &&(dd <29))) {

a = 366

} else {

a = 365

}

bday = a + (r - m - gdate)

}

nhour = 24 - parseInt(ghour)

nmin = 60 - parseInt(gmin)

nsec = 60 - parseInt(gsec)

while (bday >366) bday -= 365

if (((bday == 366) &&(leapyear(gyear)) || ((bday == 365) &&(!leapyear(gyear))))) {

document.agecalc.timealive.value += "\n\n今天是你的生日!"

} else {

document.agecalc.timealive.value += "\n\n你离下一个生日还有:\n"

+ bday + " 天 " + nhour + " 小时 " + nmin + " 分 " + nsec + " 秒"

setTimeout("run()", 1000)

}

}

function leapyear(a) {

if (((a%4 == 0) &&(a%100 != 0)) || (a%400 == 0))

return true

else

return false

}

// End -->

</script>

<form name=agecalc>

<table>

<tr><td align=center>

请输入你的生日: <select name=month size=1>

<option>一月

<option>二月

<option>三月

<option>四月

<option>五月

<option>六月

<option>七月

<option>八月

<option>九月

<option>十月

<option>十一月

<option>十二月

</select>

<select name=day size=1>

<option>1

<option>2

<option>3

<option>4

<option>5

<option>6

<option>7

<option>8

<option>9

<option>10

<option>11

<option>12

<option>13

<option>14

<option>15

<option>16

<option>17

<option>18

<option>19

<option>20

<option>21

<option>22

<option>23

<option>24

<option>25

<option>26

<option>27

<option>28

<option>29

<option>30

<option>31

</select>

<input type=text name=year size=4 maxlength=4>

<br>

<input type=button name=start value="计算" onclick="run()"><br>

<br>

<textarea rows=12 cols=35 name=timealive>

或者

<html>

<head>

<title>计算年龄</title>

<style type="text/css">

<!--

body { font-family: "宋体"font-size: 9ptmargin-top: 0pxmargin-left: 4pxmargin-right: 0px}

A { COLOR: blackFONT-SIZE: 13pxFONT-WEIGHT: 400TEXT-DECORATION: none }

A:hover { COLOR: redFONT-SIZE: 13pxFONT-WEIGHT: 400TEXT-DECORATION: underline }

a:active { font: 9pt "宋体"cursor: handcolor: #FF0033 }

--></style>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">

</head>

<body OnLoad="startclock()">

<br>

<br>

<center><font color=red face="隶书" size=6>计算出生时间</font></center>

<br>

<center>

<table border=0 bordercolor=blue borderlight=green style="border-collapse: collapse" cellpadding="0" cellspacing="0">

<tr><td align=center><font size=5 color=red face="Arial, Helvetica, sans-serif"><strong>下面框中为脚本显示区</strong></font></td></tr>

<tr><td align=center height=80>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

var mm = prompt('请输入你出生的月份?','1-12')

var bday = prompt('请输入你出生在哪一天?','1-31')

var byear = prompt('请输入你出生的年份?','1975')

var year = new Date()

var year2 = year.getYear()

var year3 = (year <2000) ? year2 + 1900 : year2

thedate = new Date()

mm2 = thedate.getMonth() + 1

dd2 = thedate.getDate()

yy2 = thedate.getYear()

if (yy2 <100) yy2 += 1900

yourage = yy2 - byear

if (mm2 <mm) yourage--

if ((mm2 == mm) &&(dd2 <bday)) yourage--

TMonth = new Array(

'January','February','March',

'April','May','June','July',

'August','September','October',

'November','December'

)

CurMonth = mm - 1

bmonth = TMonth[CurMonth]

var age2 = yourage + 1

var timerID

var timerRunning = false

var today = new Date()

var startday = new Date()

var enday = new Date()

var secPerDay = 0

var minPerDay = 0

var hourPerDay = 0

var secsLeft = 0

var secsRound = 0

var secsRemain = 0

var minLeft = 0

var minRound = 0

var minRemain = 0

var timeRemain = 0

function stopclock() {

if(timerRunning)

clearTimeout(timerID)

timerRunning = false

}

function startclock() {

stopclock()

showtime()

showtime1()

}

function showtime() {

today = new Date()

enday = new Date(""+bmonth+", "+bday+" "+year3+" 00:00")

enday.setYear(""+year3+"")

secsPerDay = 1000

minPerDay = 60 * 1000

hoursPerDay = 60 * 60 * 1000

PerDay = 24 * 60 * 60 * 1000

secsLeft = (enday.getTime() - today.getTime()) / minPerDay

secsRound = Math.round(secsLeft)

secsRemain = secsLeft - secsRound

secsRemain = (secsRemain <0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60

secsRemain = Math.round(secsRemain)

minLeft = ((enday.getTime() - today.getTime()) / hoursPerDay)

minRound = Math.round(minLeft)

minRemain = minLeft - minRound

minRemain = (minRemain <0) ? minRemain = 60 - ((minRound - minLeft) * 60) : minRemain = ((minLeft - minRound) * 60)

minRemain = Math.round(minRemain - 0.495)

hoursLeft = ((enday.getTime() - today.getTime()) / PerDay)

hoursRound = Math.round(hoursLeft)

hoursRemain = hoursLeft - hoursRound

hoursRemain = (hoursRemain <0) ? hoursRemain = 24 - ((hoursRound - hoursLeft) * 24) : hoursRemain = ((hoursLeft - hoursRound) * 24)

hoursRemain = Math.round(hoursRemain - 0.5)

daysLeft = ((enday.getTime() - today.getTime()) / PerDay)

daysLeft = (daysLeft - 0.5)

daysRound = Math.round(daysLeft)

daysRemain = daysRound

if (daysRemain == 1) day_rem = " day, "

else day_rem = " 天, "

if (hoursRemain == 1) hour_rem = " hour, "

else hour_rem = " 小时, "

if (minRemain == 1) min_rem = " minute, "

else min_rem = " 分, "

if (secsRemain == 1) sec_rem = " second"

else sec_rem = " 秒"

timeRemain = daysRemain + day_rem + hoursRemain + hour_rem + minRemain + min_rem + secsRemain + sec_rem

document.down.face.value = timeRemain

timerID = setTimeout("showtime()",1000)

timerRunning = true

if (daysRemain <0) year3 = year3 + 1

}

function showtime1() {

startday = new Date(""+bmonth+" "+bday+", "+byear+" 00:00 EDT")

startday.setYear(""+byear+"")

today = new Date()

secsPerDay = 1000

minPerDay = 60 * 1000

hoursPerDay = 60 * 60 * 1000

PerDay = 24 * 60 * 60 * 1000

secsLeft = (today.getTime() - startday.getTime()) / minPerDay

secsRound = Math.round(secsLeft)

secsRemain = secsLeft - secsRound

secsRemain = (secsRemain <0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60

secsRemain = Math.round(secsRemain)

minLeft = ((today.getTime() - startday.getTime()) / hoursPerDay)

minRound = Math.round(minLeft)

minRemain = minLeft - minRound

minRemain = (minRemain <0) ? minRemain = 60 - ((minRound - minLeft) * 60) : minRemain = ((minLeft - minRound) * 60)

minRemain = Math.round(minRemain - 0.495)

hoursLeft = ((today.getTime() - startday.getTime()) / PerDay)

hoursRound = Math.round(hoursLeft)

hoursRemain = hoursLeft - hoursRound

hoursRemain = (hoursRemain <0) ? hoursRemain = 24 - ((hoursRound - hoursLeft) * 24) : hoursRemain = ((hoursLeft - hoursRound) * 24)

hoursRemain = Math.round(hoursRemain - 0.5)

daysLeft = ((today.getTime() - startday.getTime()) / PerDay)

daysLeft = (daysLeft - 0.5)

daysRound = Math.round(daysLeft)

daysRemain = daysRound

if (daysRemain == 1) day_rem = " day, "

else day_rem = " 天, "

if (hoursRemain == 1) hour_rem = " hour, "

else hour_rem = " 小时, "

if (minRemain == 1) min_rem = " minute, "

else min_rem = " 分, "

if (secsRemain == 1) sec_rem = " second"

else sec_rem = " 秒"

timeRemain = daysRemain + day_rem + hoursRemain + hour_rem + minRemain + min_rem + secsRemain + sec_rem

document.up.face.value = timeRemain

timerID = setTimeout("showtime1()",1000)

timerRunning = true

}

// End -->

</script>

<form name="down" onSubmit="0">

<script Language="JavaScript">

document.write("<b>你出生于"+bmonth+" "+bday+", "+byear+". ("+mm+"/"+bday+"/"+byear+")</b>")

document.write("<br><br>你已经 "+yourage+" 岁了,离你生日还有.")

</script>

<br>

<input type="text" name="face" size="47" value="A browser supporting JavaScript 1.1+ is needed.">

</form>

<p>

<br>

<form name="up" onSubmit="1">

你已经生活了...<br>

<input type="text" name="face" size="47" value="A browser supporting JavaScript 1.1+ is needed.">

</form>

</td></tr></table></center>

<br>

<br>

<center>

<SCRIPT LANGUAGE="JavaScript">

<!-- hide

function goHist(a)

{

history.go(a)

}

//-->

</script>

</center>

<br>

<center>

<br>

<br>

</body>

</html>

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>Title</title>

</head>

<body>

 <!-- 给两个Select标签一个id方便Javascript定位 -->

<label for="yselect">年份:</label>

<select id="yselect">

    <option value=""></option>

</select>

<label for="mselect">月份:</label>

<select id="mselect">

    <option value=""></option>

</select>

<script>

 let YearSelect = document.querySelector('#yselect')

 //定位年份

 for (let i = 2018 i > 1918 i--) {//从2018一直输出到1919

 let tmpElement = document.createElement('option')

 //创建一个选项元素

 tmpElement.value = i

 //赋值(Post等表单 *** 作输送的赋值)

 tmpElement.id = "yoption" + i

 //给id方便以后 *** 作

 tmpElement.innerText = i

 //填上内容方便用户选择

 YearSelect.appendChild(tmpElement)

 //将元素扔到年份选择标签的最下面的元素,保证是第一个是2018最后一个是1919

 }

 let MonthSelect=  document.querySelector('#mselect')

 for (let i = 12 i > 0 i--) {

 let tmpElement = document.createElement('option')

 tmpElement.value = i

 tmpElement.id = "moption" + i

 tmpElement.innerText = i

 MonthSelect.appendChild(tmpElement)

 }

 //同理

</script>

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/7262307.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-03
下一篇2023-04-03

发表评论

登录后才能评论

评论列表(0条)

    保存