简体   繁体   English

这段代码是什么意思?

[英]What is this code's meaning?

I was designing a webpage and encountered the following code written in javascript I want to know if it's ok if i remove this code and add my own code or does it create any problems Note: This was an code found in an HTML5 Template 我正在设计一个网页,遇到以下用javascript编写的代码,我想知道是否可以删除该代码并添加自己的代码,否则会造成任何问题。注意:这是在HTML5模板中找到的代码

Here is the code: 这是代码:

var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
elems.forEach(function(html) {
    var switchery = new Switchery(html);
}

This code selects all HTML elements that have a CSS class of js-switch applied and creates a new Switchery object for each of them. 此代码选择所有应用了js-switch CSS类的HTML元素,并为每个HTML元素创建一个新的Switchery对象。 Since you didn't provide much context I have to guess but it's very likely that this will turn standard HTML checkboxes into iOS-style switches. 由于您没有提供太多上下文,因此我不得不猜测,但是很有可能会将标准HTML复选框变成iOS样式的开关。

See also the Switchery homepage for more information: http://abpetkov.github.io/switchery/ 另请参阅Switchery主页以获取更多信息: http : //abpetkov.github.io/switchery/

Whether this code is needed or not might be a design decision. 是否需要此代码可能是设计决策。 It'll only change the visual appearance but the sliders still behave like checkboxes. 它只会改变外观,但滑块的行为仍像复选框一样。 It might, however, be worth checking whether your site actually contains any HTML checkboxes with the js-switch class applied. 但是,值得检查您的站点是否实际上包含应用了js-switch类的HTML复选框。 If not, that code can definitely be dropped. 如果没有,则绝对可以删除该代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM