roy-tian / learning-area Goto Github PK
View Code? Open in Web Editor NEWMDN 学习区示例中文版
License: Creative Commons Zero v1.0 Universal
MDN 学习区示例中文版
License: Creative Commons Zero v1.0 Universal
when I click a "raw" button, the firfox can't copy it properly. It jumps to error pages.
I follow the steps
and add <script> and <style>
I can not get same result like that.
So I checked. the console gives this error
I found some pages that said <script> should be after the body.
I tried it works.
In the meta-example.html there has "defer". It means after HTML body loaded , load this.
<script src="script.js" defer></script>
My point is this, learn page does not include what is defer means.
could you add this defer information on MDN learn page? (https://developer.mozilla.org/zh-CN/docs/learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML)
function result() {
let isCN = document.getElementById("cn").checked;
let newStory = isCN ? storyTextZh : storyText;
let insert0 = isCN ? insertA : insertX;
let insert1 = isCN ? insertB : insertY;
let insert2 = isCN ? insertC : insertZ;
let replace0 = isCN ? ':inserta:' : ':insertx:';
let replace1 = isCN ? ':insertb:' : ':inserty:';
let replace2 = isCN ? ':insertc:' : ':insertz:';
let placeName = isCN ? '李雷' : 'Bob';
newStory = newStory.replace(replace0, randomValueFromArray(insert0));
newStory = newStory.replace(replace0, randomValueFromArray(insert0));
newStory = newStory.replace(replace1, randomValueFromArray(insert1));
newStory = newStory.replace(replace2, randomValueFromArray(insert2));
if(customName.value !== '') {
var name = customName.value;
newStory = newStory.replace(placeName, name);
}
if(document.getElementById("uk").checked) {
const weight = Math.round(300 * 0.0714286) + ' stone';
const temperature = Math.round((94 - 32) * 5 / 9) + ' centigrade';
newStory = newStory.replace('94 fahrenheit', temperature);
newStory = newStory.replace('300 pounds', weight);
}
story.textContent = newStory;
story.style.visibility = 'visible';
}
在笑话机的main.js文件中,第 24 与第 35 行代码相同,是 Shift
+ Alt
+ ↓
按秃噜了吗😂
function result() {
let isCN = document.getElementById("cn").checked;
let newStory = isCN ? storyTextZh : storyText;
let insert0 = isCN ? insertA : insertX;
let insert1 = isCN ? insertB : insertY;
let insert2 = isCN ? insertC : insertZ;
let replace0 = isCN ? ':inserta:' : ':insertx:';
let replace1 = isCN ? ':insertb:' : ':inserty:';
let replace2 = isCN ? ':insertc:' : ':insertz:';
let placeName = isCN ? '李雷' : 'Bob';
newStory = newStory.replace(replace0, randomValueFromArray(insert0));
newStory = newStory.replace(replace0, randomValueFromArray(insert0));
newStory = newStory.replace(replace1, randomValueFromArray(insert1));
newStory = newStory.replace(replace2, randomValueFromArray(insert2));
if(customName.value !== '') {
var name = customName.value;
newStory = newStory.replace(placeName, name);
}
if(document.getElementById("uk").checked) {
const weight = Math.round(300 * 0.0714286) + ' stone';
const temperature = Math.round((94 - 32) * 5 / 9) + ' centigrade';
newStory = newStory.replace('94 fahrenheit', temperature);
newStory = newStory.replace('300 pounds', weight);
}
story.textContent = newStory;
story.style.visibility = 'visible';
}
很多章节的js文件中都是进行操作DOM,又没有DOMContentLoaded的,而在HTML中它们几乎都是用的<script async>
这种形式的标签。
<head>
<script src="script.js" async></script>
</head>
但查其他资料却都是说 async 异步加载完立刻执行,最好不要用于上面那种操作DOM的情况:Script Tag - async & defer
而 MDN 的入门文档却说这样用是对的,比如 什么是 JavaScript? 里介绍如何避免在解析HTML文档之前调用javascript的部分:
【在上文的“内部”、“外部”示例中,JavaScript 调用于文档头处,解析 HTML 文档体之前。这样做是有隐患的,需要使用一些结构来避免错误发生。】
【“内部”示例使用了以下结构:这是一个事件监听器,它监听浏览器的 "DOMContentLoaded" 事件,即 HTML 文档体加载、解释完毕事件。事件触发时将调用 " . . ." 处的代码,从而避免了错误发生(事件 的概念稍后学习)。】
【“外部”示例中使用了 JavaScript 的一项现代技术(async “异步”属性)来解决这一问题,它告知浏览器在遇到 <script> 元素时不要中断后续 HTML 内容的加载。注:“外部”示例中 async 属性可以解决调用顺序问题,因此无需使用 DOMContentLoaded 事件。而 async 只能用于外部脚本,因此不适用于“内部”示例。】
再比如笑话生成器 的示例代码。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.