fan123456 发表于 2020-10-1 11:23:51

javasprict

题目是创建一个页面,显示当前的年月日时分秒星期几,点击当前的日期弹出消息框,“祝你一天幸福美满”, 前面都会就是后面那个点击日期弹出消息框不知道怎么弄,求助大神

aaron.yang 发表于 2020-10-1 11:57:48

本帖最后由 aaron.yang 于 2020-10-1 12:12 编辑

<html>
    <head>
      <meta charset="UTF-8">
      <title> test </title>
    </head>
    <body>
      <button id="date" onclick="f()"></button>
      <script>
            var date = Date(), button_id = document.getElementById("date");
            var date_slice = date.slice(4, 23);
            button_id.innerHTML = date_slice;
            function f()
            {
                alert("祝你一天幸福美满");
            }
      </script>
    </body>
</html>

fan123456 发表于 2020-10-1 12:36:39

aaron.yang 发表于 2020-10-1 11:57


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function changetext(id){
       id.innerhtml="祝你一天幸福美满";
       }
       </script>
</head>

<body>
<h1 onclick="changetext(this)">
<script type="text/javascript">
var now, year, month, date, hour, minute, second, day, time;
now = new Date();
year = now.getFullYear();
month = now.getMonth() + 1;
date = now.getDate();
hour = now.getHours();
minute = now.getMinutes();
second = now.getSeconds();
if(month < 10) month = "0" + month;
if(date < 10) date = "0" + date;
if(hour < 10) hour = "0" + hour;
if(minute < 10) minute = "0" + minute;
if(second < 10) second = "0" + second;

day = now.getDay();
switch(day) {
case 0: day = "星期日"; break;
case 1: day = "星期一"; break;
case 2: day = "星期二"; break;
case 3: day = "星期三"; break;
case 4: day = "星期四"; break;
case 5: day = "星期五"; break;
case 6: day = "星期六"; break;
}
time = year + "年" + month + "月" + date + "日" + day;
time = time + " " + hour + ":" + minute + ":" + second;
document.write(time);
</script></h1>
<p id="demo"></p>
</body>
</html>
这是我代码运行出不来弹窗 大佬看看哪里错了

kmq116 发表于 2020-10-4 02:17:14

alert
页: [1]
查看完整版本: javasprict