第十二章 Javaweb Document对象

本文介绍了一种使用JavaScript生成10-99范围内10个不同随机奇数的方法,同时涵盖了Document对象、Cookie属性及Location对象的基本概念,适合初学者理解JS核心功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

找出10 - 99 中的10个不同的随机奇偶数

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<script type="text/javascript">
var a = new Array();
for(var i = 1;i <= 10;i++){
	x = 2 * parseInt(5 + 45 * Math.random()) + 1;
	while(a.indexOf(x) > 0)
	x = 2 * parseInt(5 + 45 * Math.random()) + 1;
	a.push(x);
}
document.write(a + "<br>");
</script>
</body>
</html

Document对象

Document对象是指在浏览器窗口显示的HTML文档。Document对象作为Window对象包含下的一个对象, 可以利用"window.document" 访问文档的属性和方法。 如果当前窗体中包含框架对象, 可以使用表达式“window.frames(n).document” 来访问框架对象中显示的Document对象, 式中的“n”表示框架对象在当前窗口的索引号。
在这里插入图片描述

Cookie属性

Cookie是一段信息字符串, 由浏览器保存在客户端的cookie文件中, 包含了客户机的状态信息。 这些信息服务器都可以访问。
该属性是一个可读可写的字符串吗可使用该属性对当前文档的cookie进行读取, 创建, 修改和删除。
document.cookie = sCookie.
在这里插入图片描述在这里插入图片描述
write与writeln的区别(无区别)

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script language="javascript">
document.writeln("Hello word<br>");
document.writeln("好好学习<br>");
document.writeln("天天向上<br>");
</script>
</body>
</html>

返回指定名称的对象集合

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<input type = "text" name = "text" value = "a" /><br/>
<input type = "text" name = "text" value = "b" /><br/>
<input type = "text" name = "text" value = "c" /><br/>
<input type = "text" name = "text" value = "d" /><br/>


<script language="javascript">
	var text = document.getElementsByName('text');
	document.write(text.length + "<br>");
	for(var i = 0;i < text.length;i++)
	document.write(text[i].value);
</script>
</body>
</html>

Location对象

在这里插入图片描述# History
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值