Summary of skills in css and html, click here to go to: Summary of some common skills in front-end development. You can also go to Lanzhi blog to view the front-end tips compiled by Taobao UED: http:///category/css/.
1. Abbreviation:https:///article/;
2. The abbreviation of getElementsByTagName:https:///article/;
3. Functions that get element index in native JavaScript:https:///article/;
4. Instead, loading functions that can be called multiple times:
function iLoad(func) {
var oLoad=;
if(typeof !='function'){
=func;
}else{
=function(){
oLoad();
func();
}
}
}
5. Get the next element node:
function nextElem(node){
if(==1) return node;
if() return nextElem();
return null;
}
6. Get the previous element node (this function must call the function in Article 5):
function prevElem(node){
if(==1){
return node;
}else if(){
return nextElem();
}else{
return null;
}
}
7. There is an insertBefore method in native JavaScript, but unfortunately there is no insertAfter method. What should I do? Use the following function to implement it:
function insertAfter(newChild,refChild){
var parElem=;
if(==refChild){
(newChild);
}else{
(newChild,);
}
}
8. Add style to the element [remember to add, not replace, equivalent to addClass(value) in jQuery]:
function addClass(elem,value){
if(!){
=value;
}else{
var oValue=;
oValue+=" ";
oValue+=value;
=oValue;
}
}
9. Get the style of the element:
function getStyle(id,stylename){
var elem=$(id);
var realStyle=null;
if(){
realStyle=[stylename];
}else if(){
realStyle=(elem,null)[stylename];
}
return realStyle;
}
10. Compatible event binding:
function addEventSamp(obj,evt,fn){
if () {
(evt, fn, false);
}else if(){
('on'+evt,fn);
}
}
11. Remove Events
function removeEventSamp(obj,evt,fn){
if(){
(evt,fn,false);
}else if(){
('on'+evt,fn);
}
}
12. Detection style
function hasClass(element, className){
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
return (reg);
}
13. Delete styles
function removeClass(element, className){
if (hasClass(element, className)) {
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
= (reg, ' ');
}
}
Original blog post:/javascript-common-function-tip/
$()
function $() {
var elements = [];
for (var i = 0; i < ; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = (element);
if ( == 1)
return element;
(element);
}
return elements;
}
toggle()
Used to display or hide a DOM element.
function toggle(obj) {
var el = (obj);
=( !="none"?"none":"")
}
1. Abbreviation:https:///article/;
2. The abbreviation of getElementsByTagName:https:///article/;
3. Functions that get element index in native JavaScript:https:///article/;
4. Instead, loading functions that can be called multiple times:
Copy the codeThe code is as follows:
function iLoad(func) {
var oLoad=;
if(typeof !='function'){
=func;
}else{
=function(){
oLoad();
func();
}
}
}
5. Get the next element node:
Copy the codeThe code is as follows:
function nextElem(node){
if(==1) return node;
if() return nextElem();
return null;
}
6. Get the previous element node (this function must call the function in Article 5):
Copy the codeThe code is as follows:
function prevElem(node){
if(==1){
return node;
}else if(){
return nextElem();
}else{
return null;
}
}
7. There is an insertBefore method in native JavaScript, but unfortunately there is no insertAfter method. What should I do? Use the following function to implement it:
Copy the codeThe code is as follows:
function insertAfter(newChild,refChild){
var parElem=;
if(==refChild){
(newChild);
}else{
(newChild,);
}
}
8. Add style to the element [remember to add, not replace, equivalent to addClass(value) in jQuery]:
Copy the codeThe code is as follows:
function addClass(elem,value){
if(!){
=value;
}else{
var oValue=;
oValue+=" ";
oValue+=value;
=oValue;
}
}
9. Get the style of the element:
Copy the codeThe code is as follows:
function getStyle(id,stylename){
var elem=$(id);
var realStyle=null;
if(){
realStyle=[stylename];
}else if(){
realStyle=(elem,null)[stylename];
}
return realStyle;
}
10. Compatible event binding:
Copy the codeThe code is as follows:
function addEventSamp(obj,evt,fn){
if () {
(evt, fn, false);
}else if(){
('on'+evt,fn);
}
}
11. Remove Events
Copy the codeThe code is as follows:
function removeEventSamp(obj,evt,fn){
if(){
(evt,fn,false);
}else if(){
('on'+evt,fn);
}
}
12. Detection style
Copy the codeThe code is as follows:
function hasClass(element, className){
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
return (reg);
}
13. Delete styles
Copy the codeThe code is as follows:
function removeClass(element, className){
if (hasClass(element, className)) {
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
= (reg, ' ');
}
}
Original blog post:/javascript-common-function-tip/
$()
Copy the codeThe code is as follows:
function $() {
var elements = [];
for (var i = 0; i < ; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = (element);
if ( == 1)
return element;
(element);
}
return elements;
}
toggle()
Used to display or hide a DOM element.
Copy the codeThe code is as follows:
function toggle(obj) {
var el = (obj);
=( !="none"?"none":"")
}