document.write("<font size='5' color='____'>"+tips[i]+"</font>"); </script> </body> </html>
时间: 2024-05-27 18:05:06 浏览: 11
以下是一个JavaScript的例子,演示了如何使用document.write在HTML中输出文本:
```javascript
<script>
var tips = ["Tip 1", "Tip 2", "Tip 3"];
for (var i = 0; i < tips.length; i++) {
document.write("<font size='5' color='blue'>"+tips[i]+"</font><br>");
}
</script>
```
这段代码会在HTML页面中输出一个带有不同颜色和字体大小的文本。每个提示都会以新的一行显示。
相关问题
for (var i = 0; i <= 13; i++) { if (i == 0) { //添加周信息 document.write('<tr class="headCourse"><th class="th_course"></th><th class="th_course">周一</th><th class="th_course">周二</th><th class="th_course">周三</th><th class="th_course">周四</th><th class="th_course">周五</th><th class="th_course">周六</th><th class="th_course">周天</th></tr >'); } else { //添加时段信息 //<tr class="j1"></tr> document.write('<tr class="j' + i + '"></tr>'); tr_ = $(".j" + i); //<th>1</th> tr_.document.write('<th class="th_course">' + i + '</th>'); for (var j = 1; j <= 7; j++) { //<td id="w1_j1"></td> tr_.document.write('<td id="w' + j + '_j' + i + '" class="td_course"></td>'); } } }
这段代码是用 JavaScript 写的,它用于生成一个表格,表格包含周一至周日的课程安排,共有 14 行,第一行是表头,其余 13 行分别代表一天的每一个时段。具体来说,它通过循环生成每一行,并在每一行中生成对应的单元格,其中第一列显示时段信息,后面七列分别显示周一至周日的课程安排。每个单元格的 id 属性是根据其所在的行列位置生成的,方便后续对单元格进行操作。
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> <script type="text/javascript"> var date = new Date(); var today = date.getDate(); var month = date.getMonth(); var week = date.getDay(); document.write("日 一 二 三 四 五 六<br>"); for(var i=0;i<=week;i++) { document.write(" "); } var temp = 1; date.setDate(temp) while(date.getMonth()== month) { var currentDate = date.getDate(); if(currentDate <10) document.write("0"); if(currentDate ==today) document.write("<font color =red>"+currentDate+"</font>"); else document.write(currentDate+" "); if(date.getDay() == 6) document.write("<br>"); temp++; date.setDate(temp) } </script> <body> </body> </html>完善这个代码
这段代码主要是用来生成一个日历,并且将当天日期标记为红色。以下是完善后的代码:
```
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>日历</title>
</head>
<body>
<script type="text/javascript">
var date = new Date();
var today = date.getDate();
var month = date.getMonth();
var week = date.getDay();
document.write("<table>"); // 添加表格标签
document.write("<tr><th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr>"); // 添加表头
for(var i=0;i<=week;i++) {
document.write("<td></td>"); // 添加空白单元格
}
var temp = 1;
date.setDate(temp);
while(date.getMonth()== month) {
var currentDate = date.getDate();
if(currentDate <10) {
document.write("0");
}
if(currentDate ==today) {
document.write("<td><font color='red'>"+currentDate+"</font></td>"); // 当天日期标红
} else {
document.write("<td>"+currentDate+"</td>");
}
if(date.getDay() == 6) {
document.write("</tr><tr>"); // 换行
}
temp++;
date.setDate(temp);
}
document.write("</tr></table>"); // 关闭表格标签
</script>
</body>
</html>
```
在这个代码中,我们添加了一个表格标签 `<table>` 和一个表头标签 `<tr><th>...</th></tr>`,并且在每一行的开头添加了一个空白单元格 `<td></td>`。同时,当天日期的单元格使用了 `<font>` 标签来设置颜色。最后,在代码结束之前,我们添加了一个关闭表格标签 `</table>`。这样,我们就可以生成一个更加完整的日历了。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
- <input type="number" class="gnum c_pt" id ="gnumCpt" value="1"/>+ - <input type="number" class="gnum c_pt" id ="gnumCpt" value="1"/>+ 减不能小于1,并实现乘除算法输出结果在一个标签里。 ¥13500.00 全选 去结算(3) 共计:¥148000 总额:¥148000,优惠¥0 - <input type="number" class="gnum c_pt" id ="gnumCpt" value="1"/> + 全选 去结算(2) 共计:¥{{goods_price}} 总额:¥179000,优惠¥0 并将idw为gnumCpt的value值乘class为ca_jg的数,显示在b标签id为count里
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)