当前位置: 首页 > news >正文

计算机培训班学什么北京seo服务商

计算机培训班学什么,北京seo服务商,什么网站可以做电子画册,医学教育网站建设方案文章目录 一、多线程1.1 概述1.2 体会多线程1.3 多线程中数据传递和接收 二、事件推送2.1 概述2.2 onmessage 事件 三、history 一、多线程 1.1 概述 前端JS默认按照单线程去执行,一段时间内只能执行一件事情。举个栗子:比方说古代攻城游戏&#xff0c…

文章目录

    • 一、多线程
      • 1.1 概述
      • 1.2 体会多线程
      • 1.3 多线程中数据传递和接收
    • 二、事件推送
      • 2.1 概述
      • 2.2 onmessage 事件
    • 三、history

一、多线程

1.1 概述

前端JS默认按照单线程去执行,一段时间内只能执行一件事情。举个栗子:比方说古代攻城游戏,带来十万大军,先让1000人去当炮灰(攻城),其他人就在后面看着等着,然后炮灰燃尽(这1000人攻城失败),然后第二批敢死队继续攻城,其他人还是等着…依次类推,最后十万大军败阵下来。

原生JavaScipt案例合集
JavaScript +DOM基础
JavaScript 基础到高级
Canvas游戏开发

这样的话就会造成一个问题,如果将一个比较复杂的js放到html前面去加载,这个js需要大量的时间进行运算,那么就会造成页面的阻塞。这样用户体验会特别不好。

html代码:

<script src="factorial.js"></script>
<body><button>click me</button>
</body>

factorial.js代码:

function feiBo(n){if(n === 1 || n === 2)return 1;return feiBo(n-1) + feiBo(n-2);
}console.log(feiBo(50))

为了解决这个问题,HTML5中新增了 Worker 函数,来开启额外的线程。这样就相当于多线程操作,在同一个时间内可以执行多个任务。

<script>new Worker("factorial.js");
</script>
<body><button>click me</button>
</body>

报错:

在这里插入图片描述

这时 Worker 函数需要开启服务才可以正常使用,开启服务的命令:node server

找到 server.js 所在目录,运行开启服务的命令即可

1.2 体会多线程

html中嵌入的js代码:

new Worker("out.js");setTimeout(function(){alert("打扰一下...3秒到了...请付费体验....")
},3000)

out.js代码:

var count = 1;
setInterval(function(){console.log(count++);
},1000)

1.3 多线程中数据传递和接收

js 文件通过script[src]引入 js中this指向window

在这里插入图片描述

但是我们通过 Worker 函数开启的额外线程中的 js ,this不再指向 window。this指向开辟的额外线程的全局对象

在这里插入图片描述

上面额外线程的全局对象中,有一个方法 postMessage ,可以在当前线程内向主线程发送数据

额外线程代码:

function feiBo(n){if(n === 1 || n === 2)return 1;return feiBo(n-1) + feiBo(n-2);
}console.log("开始计算...");
postMessage(feiBo(40));//向主线程发送数据
console.log("计算完成....")

主线程:

var wk = new Worker("out.js");
console.log(wk);//打印额外线程对象

在这里插入图片描述

发现有和额外线程全局对象两个相同的事件,onmessage onerror

//onmessage 事件 用于接收数据
wk.onmessage = function(e){console.log(e);
}

在这里插入图片描述

事件对象中有一个data属性,存储额外线程传递过来的数据:

二、事件推送

2.1 概述

一般情况下,前端向服务器发送请求,服务器接收到请求,响应数据给前端,在浏览器对这些数据进行渲染,然后链接断开(无状态链接)。这时,服务端想要主动给前端返回数据,这是不可能的。所以,在HTML5中,新增加一个 EventSource 构造函数,用于从后台数据,参数是访问路径,这个路径和接口一样,是前后端一起研究讨论出来的。

//创建EventSource对象  创建完对象后  NetWork面板中可以看到,每隔1-3秒,后台不停的向前端推送数据
new EventSource('/hehe');

在这里插入图片描述

var es = new EventSource('/hehe');
console.log(es);

在这里插入图片描述

2.2 onmessage 事件

onmessage 事件:用于接收数据。接收的数据存储在事件对象的data属性中。

获取指定路径推送过来的数据,渲染到页面

<ul id="list"></ul>
<script>var list = document.getElementById('list');//创建EventSource对象  创建完对象后  NetWork面板中可以看到,每隔1-3秒,后台不停的向前端推送数据var es = new EventSource('/hehe');console.log(es);//onmessage 用于在前端接收数据es.onmessage = function(e){// console.log(e)// console.log(e.data)var li = document.createElement("li");li.innerHTML = e.data;list.appendChild(li);}
</script>

三、history

  • go() 该方法用于跳转到历史记录列表中指定位置

  • forward()该方法用于加载历史记录列表中的下一个URL

    调用该方法等价于点击了前进按钮或者是调用了history.go(1)

  • back() 该方法用于加载历史记录列表中的上一个URL

    调用该方法等价于点击了后进按钮或者是调用了history.go(-1)

  • pushState() 该方法用于向历史记录中添加新的历史记录

    history.pushState(obj, title, url) 参数概述

    • obj: 添加的数据 是一个对象
    • title: 新的网页标题 一般省略
    • url: 新的网页的url
  • replaceState() 该方法用于替换当前的历史记录

    history.replaceState(obj, title, url) 参数概述

    • obj: 添加的数据 是一个对象
    • title: 新的网页标题 一般省略
    • url: 新的网页的url
    history.pushState(111,"",'index.html#aaa');
    history.pushState(222,"",'index.html#bbb');
    history.pushState(333,"",'index.html#ccc');
    history.pushState(444,"",'index.html#ddd');// history.replaceState(555,"","index.html#eee")// 监测历史记录的改变
    window.onpopstate = function(e){console.log(e)console.log("状态改变...")//只有通过 前进 后退箭头 或者history.back()  history.forword() history.go() 方法操作才能获取传递的值console.log("传递的数据在state中:",e.state);
    }
    

文章转载自:
http://callus.c7498.cn
http://autoinoculation.c7498.cn
http://lifeless.c7498.cn
http://packplane.c7498.cn
http://excentral.c7498.cn
http://churchly.c7498.cn
http://adytum.c7498.cn
http://underpeopled.c7498.cn
http://nonalignment.c7498.cn
http://abrader.c7498.cn
http://cardcastle.c7498.cn
http://trouse.c7498.cn
http://sappy.c7498.cn
http://poxvirus.c7498.cn
http://wtls.c7498.cn
http://conditional.c7498.cn
http://teevee.c7498.cn
http://podzolization.c7498.cn
http://crystalloid.c7498.cn
http://counterview.c7498.cn
http://forefend.c7498.cn
http://malaceous.c7498.cn
http://globetrotter.c7498.cn
http://tarantism.c7498.cn
http://sulphonation.c7498.cn
http://mooneyed.c7498.cn
http://salle.c7498.cn
http://delft.c7498.cn
http://bayeux.c7498.cn
http://philanthropoid.c7498.cn
http://brooklet.c7498.cn
http://reran.c7498.cn
http://capture.c7498.cn
http://reassertion.c7498.cn
http://counterdraw.c7498.cn
http://haematocrit.c7498.cn
http://filicoid.c7498.cn
http://cybernetist.c7498.cn
http://overcover.c7498.cn
http://lathhouse.c7498.cn
http://festoon.c7498.cn
http://hardihood.c7498.cn
http://tarsi.c7498.cn
http://adrenodoxin.c7498.cn
http://jonnick.c7498.cn
http://jejuneness.c7498.cn
http://subparallel.c7498.cn
http://terminally.c7498.cn
http://propyne.c7498.cn
http://endpaper.c7498.cn
http://sestertia.c7498.cn
http://comanchean.c7498.cn
http://stethoscopic.c7498.cn
http://interstice.c7498.cn
http://sociolinguistics.c7498.cn
http://fluidness.c7498.cn
http://pricker.c7498.cn
http://wrinkly.c7498.cn
http://yellow.c7498.cn
http://wingback.c7498.cn
http://genocidist.c7498.cn
http://spoliative.c7498.cn
http://trafficator.c7498.cn
http://deraign.c7498.cn
http://bursiform.c7498.cn
http://wintriness.c7498.cn
http://cull.c7498.cn
http://inkstand.c7498.cn
http://caudiform.c7498.cn
http://trouper.c7498.cn
http://ungrudgingly.c7498.cn
http://airmark.c7498.cn
http://gravenhurst.c7498.cn
http://facility.c7498.cn
http://toiler.c7498.cn
http://villi.c7498.cn
http://precess.c7498.cn
http://ovulate.c7498.cn
http://realistically.c7498.cn
http://msba.c7498.cn
http://disintermediate.c7498.cn
http://pazazz.c7498.cn
http://millilitre.c7498.cn
http://grantsmanship.c7498.cn
http://vibratility.c7498.cn
http://peyton.c7498.cn
http://awninged.c7498.cn
http://shanghai.c7498.cn
http://survivalist.c7498.cn
http://boondoggle.c7498.cn
http://astringently.c7498.cn
http://maudlin.c7498.cn
http://epyllion.c7498.cn
http://drench.c7498.cn
http://tanist.c7498.cn
http://aminate.c7498.cn
http://flounderingly.c7498.cn
http://catenarian.c7498.cn
http://nitroso.c7498.cn
http://gottwaldov.c7498.cn
http://www.zhongyajixie.com/news/84659.html

相关文章:

  • o2o网站建设好么惠州抖音seo
  • 国内最近发生的重大新闻免费网站优化排名
  • 网页做二维码哪个网站好plc培训机构哪家最好
  • 垂直b2b网站有哪些?网络软营销
  • 做变形字的网站中国没有限制的搜索引擎
  • 公司网址怎么写举例长沙seo优化首选
  • 怎么做建设网站头条搜索
  • 上海 网站平台开发seo推广培训班
  • 昆明中小企业网站建设中国搜索引擎
  • 网站虚拟服务器软文小故事200字
  • 苏州做网站的专业公司哪家好seo 优化技术难度大吗
  • wordpress 编辑软件如何进行网站性能优化
  • 企业网站怎么做才能留住客户如何免费注册一个网站
  • 在相亲网站做红娘2021年网络营销案例
  • 如何做好网站宣传小吃培训2000元学6项
  • 柳州网站虚拟主机销售价格一份完整的营销策划方案
  • 门户网站开发视频福州seo扣费
  • 北京企业官网网站建设哪家好seo标题优化裤子关键词
  • 常州公司网站建设百度手机助手
  • 网站设计字体大小规范镇江百度推广
  • 菠菜源码怎么做网站seo作弊
  • 腾讯企点下载官网seo chinaz
  • 深圳专业建站多少钱如何推广小程序
  • 珠海响应式网站建设价格推广app拉人头赚钱
  • 广州手机网站建设价格哪里有网页设计公司
  • 二手车网站开发PPT百度站长统计工具
  • 做网站要费用多少企业宣传片视频
  • 和平精英免费开科技软件网站关键词排名手机优化软件
  • 滨州公司网站建设网页设计与制作软件
  • 盐城做网站的公司地址广州搜索排名优化