JSLite - core methods
If you have any questions, you are welcome to communicate in these places, and you are welcome to join the JSLite.io organization team for joint development!
$()
$(selector) //⇒ Select node
$("") //⇒ Generate node
$("htmlString") //⇒ Generate
JSLite(function($){ .. . }) //⇒ Equivalent to ready
$("#box") //⇒ 返回节点数组 //⇒ [<div>…</div>] $("<div></div>") //⇒ 生成div节点 //JSLite(func) 相当于ready JSLite(function($){ console.log("在节点加载完成之后执行") }) //$(func) 相当于ready $(function($){ console.log("在节点加载完成之后执行") })
JSLite()
is the same as
$()
.
noConflict
noConflict()
method transfers the JSLite
control of the variable $ to resolve the $ conflict between the two libraries.
This method releases JSLite
's control over the $
variable.
This method can also be used to specify new custom names for JSLite
variables.
General
$.noConflict(); JSLite(document).ready(function($) { // 使用 JSLite $ 的代码 }); // 使用其他库的 $ 的代码
Map back to the original object
Map the object referenced by $
back to the original object:
JSLite.noConflict(); JSLite("div p").hide(); // 使用 JSLite $("content").style.display = "none"; // 使用其他库的 $()
Restore Use alias
Revert to using alias $
, then create and execute a function that still has $
as JSLite
in its scope alias to use. In this function, the original $
object is invalid. This function is very effective for most plug-ins that do not rely on other libraries:
JSLite.noConflict(); (function($) { $(function() { // 使用 $ 作为 JSLite 别名的代码 }); })(JSLite); ... // 其他用 $ 作为别名的库的代码
abbreviation
You can replace JSLite.noConflict()
with the abbreviation ready
Combine to make the code more compact
JSLite.noConflict()(function(){ // 使用 JSLite 的代码 console.log($("div")) });
Create an alias
Create a new alias for use in the next library JSLite
Object:
var j = JSLite.noConflict(); j("#box").hide(); // 基于 JSLite 的代码 $("content").style.display = "none"; // 基于其他库的 $() 代码
New namespace
Completely move JSLite
to a new namespace:
var dom = {}; dom.jslite = JSLite.noConflict(true);
Result:
dom.jslite("div p").hide(); // 新 JSLite 的代码 $("content").style.display = "none"; // 另一个库 $() 的代码 JSLite("div > p").hide(); // 另一个版本 JSLite 的代码