js bom and dom

以下的代码只是一些小的例子。我画了一张图来总结js大的结构
在这里插入图片描述

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title></title><script>//Point 1 delayer and timer (BOM browser Object Model)var delayer;var timer;//case 1 : 10s => 0svar i = 10;function calculate(){// get object htmlelement var txt = document.getElementById("txtbox");if (i != -1){txt.value = i--;}else{//stop the setIntervalwindow.clearInterval(timer);}}function start(){//timer,1s oncetimer = window.setInterval("calculate()",1000);}//case 2 : alter a mbox after 2 secondsfunction delayer(){// delay 2s a mboxwindow.setTimeout("alert('ads could be pop-up')",2000);}			//conclusion about setTimeout and setInterval , function in system ,control a thing to do.//point2 html's skip  : history /** below are a.html' code <a href = "../a.html">go to the a.html</a><button οnclick="history.back()">back</button>//when you back , then you could be forward.<button onclick = "history.forward()">forward</button>//go(+- 1)<button οnclick="history.go(-1)">back use 'history.go(-1)'</button>conclusion above  : the browser's next and last button could be done by use these*///point3 date in jsvar dt = new Date();//year now dt.getFullYear();//Year Now(2019) - 1900 = dt.getYear()dt.getYear();//0 - 11 mm in foregin , so add 1dt.getMonth();//alert(dt.getMonth() + 1);//today is a day in this week , a numberdt.getDay();alert(dt.getDay());//day in a monthdt.getDate();alert(dt.getDate());//hour in a day dt.getHours();</script></head><body><input type = "text" id = "txtbox"/><input type = "button" value = "a surprise while you click me" onclick="start()"/><br /><button onclick="delayer()">i am a ad 2s later</button>		<br /><button onclick = "window.reload()">refresh me1</button><button onclick = "window.refresh()">refresh me2</button><!--js to skip a new window--><button onclick="location.href = '../a.html'">skip</button><script> //dom document object model 文档对象模型,从前到后用js获取html页面元素,定位元素,操作元素/*页面加载事件。* window.onload = function(){var r = document.getElementById("btn");alert(r);}*/var r = document.getElementById("btn");alert(r);//null 有先后顺序,如果放在btn后面就可。function getClass(){//返回一个伪集合svar list = document.getElementsByClassName("a");for (var i = 0; i < list.length; i++){alert(list[i].innerHTML + " "+ "html标签不会解析 " + list[i].innerText + " 纯文本");}}function getTagName(){				//把list 看作树节点var list = document.getElementById("ul1");//lis 就是树节点下 通过 li 标签得到这些元素				var lis = list.getElementsByTagName("li");for(var i = 0; i < lis.length ; i++){alert(lis[i].innerText);}}function getName(){		// object nodelistvar list = document.getElementsByName("TXT_1");alert(list.value);}</script><button onclick = "" id = "btn">hello</button><ul id = "ul1"><li>.net</li><li>java</li><li>python</li></ul><ul id = "ul2"><li>js</li><li>go</li><li>html5</li></ul><ul><li class = "a">a</li><li class = "a">a</li><li class = "a">a</li></ul><br /><input type="text" name="TXT_T1"  value="AB" /><input type="text" name="TXT_T1"  value="CD" /><br /><button onclick="getClass()">get element by class</button><button onclick="getTagName()">get element by tagname</button><button onclick="getName()">get element by name</button><img src = "logo.gif" id = "jpg1"/><img src = "qie.jpg" id = "jpg2" /><input  type = "button" onclick="visible1()" value = "占位显示"/><input  type = "button" onclick="hidden1()" value = "占位隐藏"/><input  type = "button" onclick="hide()" value = "占位不显示"/><input  type = "button" onclick="dispaly()" value = "占位不隐藏"/><input  type = "button" onclick="displayShow()" value = "显示块"/><script>//图片的隐藏与显示function visible1(){var j = document.getElementById("jpg1");j.style.visibility = "visible";}function hidden1(){var h = document.getElementById("jpg1");h.style.visibility = "hidden";}function dispaly(){var d = document.getElementById("jpg1");d.style.display = "inline";}function hide(){var h = document.getElementById("jpg1");h.style.display = "none";}function displayShow(){var h = document.getElementById("jpg1");h.style.display = "block";//显示级。。。块。会占一行。}	</script></body>
</html>

Conclusion :

BOM 定义了window窗口对象,让了js有能力操作浏览器。
window的属性 history的三种方法 location.href跳转 document

window的方法
alert() confirm()返回bool prompt实现输入框 open(‘网页名’,‘名字’,‘宽高等等’) close()
setInterval计时器 setTimeOut延时器 clearInterval clearTimeOut…

DOM dom中的每个元素都是一个节点,是一个对象,根据一个节点查到得到对应的子节点
然后取值赋值。
还有根据id tagname classname name…得到元素

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/421173.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

leetcode 383 赎金信 C++

自己想的&#xff0c;一个思路两个解法&#xff0c;从字符串中的第一个唯一字符的思路搬过来的 one class Solution { public:bool canConstruct(string ransomNote, string magazine) {int table2[26]{0};for(int i0;i!magazine.length();i){table2[magazine[i]-a];}for(int …

Win32下 Qt与Lua交互使用(二):在Lua脚本中使用Qt类

话接上篇。成功配置好QtLuatoLua后&#xff0c;我们可以实现在Lua脚本中使用各个Qt的类。直接看代码吧。 #include "include/lua.hpp" #include <QWidget> #include <QApplication> #include <QFile> #include <QDebug>static int tolua_new…

1099. Build A Binary Search Tree (30)

1099. Build A Binary Search Tree (30) 时间限制100 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains o…

mysql列属性auto(mysql笔记四)

常见的的是一个字段不为null存在默认值 没值得时候才去找默认值&#xff0c;可以插入一个null到 可以为null的行里 主键&#xff1a;可以唯一标识某条记录的字段或者字段的集合 主键设置 主键不可为null,声明时自动设置为not null 字段上设置 字段名 primary key定义完字段后 …

详解html结构之间的各个关系,层级关系(以列表为例)

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title>层级关系查找元素</title></head><body><div id "div">hello<ul id ""><li>li1</li><li>li2</…

leetcode 242 有效的字母异位词 C++

和赎金信的思路一样 我想我本科时光是找不到女朋友了&#xff0c;哪怕是一个异性的好朋友也不会有了&#xff0c;男女比例4&#xff1a;1&#xff0c;哼 class Solution { public:bool isAnagram(string s, string t) {int table2[26]{0};for(char a:t){table2[a-a];}for(char…

1058. A+B in Hogwarts (20)

1058. AB in Hogwarts (20) 时间限制50 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueIf you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silve…

jquery post 同步异步总结

最近在测试,发现有些效果不对,最后发现是post的执行顺序问题,所以研究了下,写了以下总结 1.post被请求多次,解决方法: 连接加入随机数 rand""Math.random() $.post("/Control/webControl.ashx?rand "Math.random(), { Method: "LoginIn", Parem…

js对html节点的操作

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title></title><style></style><script>function copy(){//克隆节点//1&#xff0c;得到要克隆的divvar div document.body.firstElementChild;//2,复制…

leetcode 141 环形链表 C++

两种方法一个空间O(n)&#xff0c;另一个O(1)&#xff0c;时间都是O(n)。 one class Solution { public:bool hasCycle(ListNode *head) {unordered_set<ListNode*>set;while(head){if(set.count(head))return true;set.insert(head);headhead->next;}return false;}…

1056. Mice and Rice (25)

1056. Mice and Rice (25) 时间限制100 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueMice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map…

Java poi读取,写入Excel2003

Java poi读取,写入Excel2003 相关阅读&#xff1a;poi读写Excel2007:http://www.cnblogs.com/gavinYang/p/3576741.htmljxl读写excel2003/2007:http://www.cnblogs.com/gavinYang/p/3576819.html package com.gavin.operational.excle;import java.io.FileInputStream; import …

leetcode 21 合并两个有序链表 C++

因为迭代比较好理解 所以我们在这里用递归 class Solution { public:ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {if(!l1) return l2;else if(!l2) return l1;else if(l1->val<l2->val){l1->nextmergeTwoLists(l1->next,l2);return l1;}else{l2->…

1061. 判断题(15)

1061. 判断题(15) 时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, Yue判断题的评判很简单&#xff0c;本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分。 输入格式&#xff1a; 输入在第一行给出两个不超过100的正整数N和M&…

css和 js 改变html里面的定位。

css和 js 改变html里面的定位。&#xff08;三种方式&#xff09; <style type"text/css">#div1{border: 1px aquamarine solid;/*固定定位&#xff1a;此元素在整个网页的位置不变,固定某处不动*/position : fixed;left: 20px;top: 10px;}#div2{/*相对定位&am…

终端I/O之行控制函数

下列4个函数提供了终端设备的行控制能力。其中&#xff0c;filedes引用一个终端设备&#xff0c;否则出错返回&#xff0c;errno设置为ENOTTY。 #include <termios.h> int tcdrain(int filedes); int tcflow(int filedes, int action); int tcflush(int filedes, int que…

js 正则表达式实现文本验证

<style>.spa{/*js来改变span颜色*/color: red;}</style><script type"text/javascript">function checkIn(obj){//失去焦点&#xff08;鼠标离开文本框&#xff09;时验证//文本框的值var val obj.value;//拿到文本框的名字&#xff0c;用来做swi…

1060. 爱丁顿数(25)

1060. 爱丁顿数(25) 时间限制250 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, Yue英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力&#xff0c;还定义了一个“爱丁顿数”E&#xff0c;即满足有E天骑车超过E英里的最大整数E。据说爱丁顿自己的…

leetcode 203 移除链表元素 C++

注意第一个元素的处理方法 今晚还有四个题要做&#xff0c;来不及解释了&#xff0c;上代码 class Solution { public:ListNode* removeElements(ListNode* head, int val) {struct ListNode*prenew ListNode(0,head);struct ListNode*temppre;if(!temp->next) return null…

unity3d由多个部分组成一个角色

摘自http://forum.unity3d.com/threads/16485-quot-stitch-multiple-body-parts-into-one-character-quot So I have many many models. Each has a skeleton, material, etc. I want to take some of these and combine them into one so I can apply animation commands to …