Javascript is mostly used for interactivity, i.e. for something to happen when you click a button.
Javascript是互动层。例如,当我们点击按钮时网页会有什么交互。
It also controls popups, slideshows, and carousels. It adds your product to the cart and opens up the cart drawer.
Javascript也可以控制弹窗、幻灯片以及轮播效果。它可以让我们把产品加入购物车或者是点击打开购物车弹窗。
It also reloads or updates parts of the page without refreshing the entire page.
Javascript也可以让我们不用翻页或者刷新就能更新页面的内容。
Here is an example of Javascript code (between the html <script> tags).
下面是Javascript的案例(在<script>标签之间的部分)
It’s an extremely simplified cart counter. The number changes each time you click the Add to Cart button.
这段代码是购物车页面的计数器。每当我们点击添加购物车按钮时候,数量就会有变化。
<button id="AddToCartBtn">Add to Cart</button>
<p id="cart">Items in your Cart: 0</p>
<script>
let cartCount = 0;
let button = document.querySelector("#AddToCartBtn");
button.addEventListener("click", addToCart);
function addToCart() {
cartCount = cartCount + 1;
document.querySelector("cart").innerHTML = "Items in your Cart: " + cart;
}
</script>
Why I don’t teach Javascript in this book:
为什么我们在本书中不过多的讲述Javascript:
1.This book is for beginners. You must have at least intermediate skills in HTML & CSS before you can use Javascript. In other words, by the time you’re ready for Javascript, you’re not a beginner!
这本书是针对于初学者的。我们在使用Javascript之前需要掌握HTML&CSS的知识。也就是说,这本书是为初学者准备的。
2.You don’t need Javascript that much in Shopify. Especially as an amateur coder working on your own store. Even as a freelance developer, I probably only used Javascript on 20% of projects.
在Shopify编程的过程中使用到Javascript的几率不大,尤其是作为一个业余的编程者,可能目的仅仅是修改一下自己的网站。作为一个兼职开发者,我会在20%的开发案例中才用到Javascript。
3.This book is for DIY type jobs. If you maintain your own car – you might change the oil and brake pads yourself, but you would leave the transmission and engine to a mechanic. With Javascript it’s very easy to mess things up, and probably best left to professional developers.本书这是面向DIY类型的工作。如果我们有一辆汽车,我们可能需要自己更换机油和刹车片,但是发动机出了故障,我们可能就需要专业的机械师来解决。对于初学者来说,Javascript只能让我们学习变得更加复杂混乱,因此我们可以把编写Javascript这个工作交给专业的人。
4.It’s not something you can immediately apply to Shopify. You first need to spend many hours learning general Javascript skills, and there are already great teachers for this. Javascript并不一定直接就能应用于Shopify.我们需要很多时间来学习Javascript,事实上有很多教程教授Javascript的知识。
资源:
分享一些比较好的学习网站
https://javascript30.com/
https://www.codecademy.com/




