Document.write和 getElementById(ID)
在javascript中,document.write()方法;常用来网页向文档中输出内容。
示例:通过document.write()方法,向网页文档中输出了一段文字。
document.write("我爱学习--喜欢学习。");
此外,还可以以另一种方式通过document.write()方法来输出。
document.write() 以变量的方式输出。
首先,声明一个变量。
var str="hello world";
document.write(str);
其次,可以通过document.write()方法 输出 变量与字符串的组合,通过变量 拼接字符串的方式来达到我们想要输出的效果。
注意:
拼接字符串,用加号"+";
字符串用双引号""括起来。
示例:
var str="hello world" ;
document.write(str+" "+"hello world");
//在浏览器中输出的结果为:hello world hello world
最后,我们还可以通过document.write()方法 来输出html标签:同时也可以将css样式写入到标签中,注意书写格式,及引号之间的转义。
document.getElementById(ID)//获得指定id值的对象,返回对拥有指定 id 的第一个对象的引用
在一个HTML文档中,每个元素都可以设置ID和NAME属性。其中ID属性是唯一属性,不可以重复,一个ID值只能对应一个元素;而NAME属性是可以重复的,一个NAME值可以对应一组元素。所以,使用document.getElementById(ID)时返回的只有一个被选中的HTML元素;
说明:
getElementById是通过Id来设置/返回HTML标签的属性及调用其事件与方法。
用这个方法基本上可以控制页面所有标签,条件很简单,就是给每个标签分配一个ID号。
返回具有指定ID属性值的第一个对象的一个引用。
语法:
获得ID值=id的所有属性和方法
JS中经常使用它通过控件ID取得元素的值,如一个form里包含text、label等,他们都是FORM的元素,有一个分配的ID,getElementById()是取得这些元素的text值的。
Document使用方法

Document.write和 getElementById(ID)的更多相关文章
- Id.value与document.getElementById("Id").value的区别
如果标签Id在Form表单里面的话,直接Id.value就不能用了,而是要用Form.Id.value来取值或设置值 所以最好用document.getElementById("Id&quo ...
- jquery中的$("#id")与document.getElementById("id")的区别
以前一直认为jquery中的$("#id")和document.getElementByIdx_x("id")得到的效果是一样的,今天做特效的时候才发现并不是这 ...
- 获得输入框的文本document.getElementById('id').value;
<input id="demo" type="text" value="" > x=document.getElementByI ...
- function $(id){ return document.getElementById(id); }导致所有的js不能用解决办法。。。。
function $(id){ return document.getElementById(id); } document.getElementById(id) 是获得id这个元素的. 相当于定义了 ...
- document.getElementById(“id”)与$("#id")的区别
document.getElementById("id")可以直接获取当前对象, jQuery利用$("#id")获取的是一个[object Object],需 ...
- 封装document.getElementById(id)
CreateTime--2016年12月18日11:42:45Author:Marydon封装document.getElementById(Id)方法 <script type=" ...
- function $(id) { return typeof id === "string" ? document.getElementById(id) : id; }
function $(id) { return typeof id === "string" ? document.getElementById(id) : id; } 这句代 ...
- document.getElementById("id").value与$("#id").val()之间的区别
本文链接:https://blog.csdn.net/mottohlm/article/details/78364196....今天在项目中遇到这么一个JS报错:原因是代码中有这么一段:对,就是var ...
- jquery 中的 $("#id") 与 document.getElementById("id") 的区别
以前没注意过,认为jquery 中的 $("#air") 与 document.getElementById("air") 是一回事,指的是同一个东西.在今天写 ...
随机推荐
- 【第二组】Hunter-alpha版本发布报告
Alpha版本测试报告 一 BUG汇总 1.暂时无法进行注册.(打算修复) 2.用户发布任务界面图标按钮存在显示bug.(打算修复) 3.主界面下拉菜单暂无内容,无法弹出.(打算修复) 二 场景测 ...
- linux 安装 kafka&zookeeper
安装kafka 1,下载kafka. #cd /usr/local #wget wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.1.1 ...
- [Solution] 893. Groups of Special-Equivalent Strings
Difficulty: Easy Problem You are given an array A of strings. Two strings S and T are special-equiva ...
- 从 PC 卸载 Office
https://support.office.com/zh-cn/article/%E4%BB%8E-PC-%E5%8D%B8%E8%BD%BD-Office-9dd49b83-264a-477a-8 ...
- atom使用技巧
文本 批量处理 正则 空格换成换行:Atom替换换行符直接[Ctrl]+[F],然后选择正则,输入\n
- paloalto防火墙接口使用方法及实例
1.获取账号相关的唯一API KEY windows:https://x.x.x.x/api/?type=keygen&user=username&password=password ...
- linux,无法进行写操作怎么办?read-only file system
一句命令搞定: mount -o remount rw /
- WPF中textBlock 变色功能
<Window.Resources> <Storyboard x:Key="OnLoaded" RepeatBehavior="Forever" ...
- linux下ping命令出现ping: sendto: Network is unreachable
问题:ping外网出现: sendto: Network is unreachable 查看: #route Route命令 : 在数据包没有有效传递的情况下,可以利用route命令查看路由表 [ro ...
- git安装包解压后没有configure
今天在linux上安装git客户端,解压了tar包后,发现没有configure,无法安装.经查,原来是要先执行autoconf命令,执行后出现configure