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</…

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…

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 …

解决ListView 缓存机制带来的显示不正常问题

ListView加载数据原理:系统绘制ListView时&#xff0c;首先会用getCount&#xff08;&#xff09;函数得到要绘制的这个列表的长度&#xff0c;然后开始逐行绘制。然后调用getView()函数&#xff0c;在这个函数里面首先获得一个View&#xff08;简单item&#xff0c;如字符串或…

windows phone (12) 小试自定义样式

windows phone (12) 小试自定义样式 原文:windows phone (12) 小试自定义样式样式在BS开发中经常用到&#xff0c;在wp中系统也提供了解决办法&#xff0c;就是对设置的样式的一种资源共享&#xff0c;首先是共享资源的位置&#xff0c;它是在App类中&#xff0c;之前我们已经有…

xdoj判断堆栈出栈序列是否有效c++

我在leetcode上写过类似的题&#xff0c;这个代码在xdoj上只能得***50***分&#xff0c;跪求各位大佬挑挑毛病。 #include<stack> #include<iostream> #include<vector> using namespace std; int main(){vector<int>poped;stack<int>s;int n,t;…

ArrayList的remove方法(重写equals方法) 与LinkedList的常用操作

package C12_18;import java.util.ArrayList;public class joy {public static void main(String[] args) {show();//重写equals方法&#xff0c;移除集合里面的元素。public static void show() {ArrayList<dog> al new ArrayList<dog>();al.add(new dog("j…

android学习日记13--数据存储之ContentProvide

3、ContentProvider  数据在Android当中是私有的&#xff0c;当然这些数据包括文件数据和数据库数据以及一些其他类型的数据。ContentProvider实现多应用程序间的数据共享类一般利用ContentProvider为需要共享的数据定义一个URI(统一资源定位符)然后其他程序通过Context获得C…

cin,cin.get(),getline()

我势必扫清我对c的各种疑惑&#xff0c;重拾csdn水文之任 结论&#xff1a;cin在获得需要接受的东西之前&#xff0c;对缓冲区里的空格和换行符不会理睬(但是会把它们从缓冲区删去)&#xff0c;但如果达到了可以结束接受的时候&#xff0c;空格和换行符都会让cin不再接 收,并且…

Java 字节和字符流的读写+Buffered

一个关于IO流的导图 IO流字节的读写&#xff0c;实现复制 import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException;public class TestCopy {public static void main(String[] args) throws IOException {copyT…

1070. 结绳(25)

1070. 结绳(25) 时间限制200 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者CHEN, Yue给定一段一段的绳子&#xff0c;你需要把它们串成一条绳。每次串连的时候&#xff0c;是把两段绳子对折&#xff0c;再如下图所示套接在一起。这样得到的绳子又被当成是另一段绳…

Java预编译和批处理

预编译 package csdn.prepare.take;import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException;public class TestCompiling {public static void main(String[] args) {prep…

Java模拟事务Demo

Java操作Oracle事务&#xff0c;以转账为例。 转账之前 package translate.commit;import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException;public class CommitRollback…

设计模式4-创建型模式-Prototype模式

意图&#xff1a;用原型实例指定创建对象的种类&#xff0c;并且通过拷贝这些原型对象创建新的对象。 原型模式的结构比较简单&#xff0c;在使用C实现该模式时重点要注意deep copy和shallow copy的问题。prototype模式在实际使用的过程中&#xff0c;可以通过增加一个原型管理…

Android--通知之Notification

前言 之前一篇博客讲了Android下使用Toast的方式提示消息。这篇博客讲解一下在Android中使用Notification提示消息给用户&#xff0c;Notification是一种具有全局效果的通知&#xff0c;程序一般通过NotificationManager服务来发送Notification。在本篇博客中&#xff0c;将介绍…