


A cssQuery object javascript script implementation code_js object-oriented
/**
* @author Supersha
* @QQ:770104121
*/
var cssQuery = {
//parent: used to store a reference to the parent node of the current node
parent: document,
select: function(selectorStr){
var selectors=selectorStr.split(" "); // Separated string
for (var i = 0, len = selectors.length; i < len; i ) {
var el = this.parent || document; //Node used to store specified class attributes Reference
var val=this.replaceStr(selectors[i]); //Replace the "#" and "." dots to obtain the node reference of the specified ID
if (selectors.length == 1) { //If there is only one parameter
if (!(/[#.]/g).test(selectors[i])) { //If it is an HTML tag
return document.getElementsByTagName(selectors[ i]);
}
else { //If it is an ID or a specified class value
//Determine whether it is an ID or a class attribute
return (this.IDLabel(selectors[i]))? this.$(val) : this.getElementsByClassName(document, "*", val);
}
}
//If the last ID or class or HTML tag in the selectorStr character is reached
else if(i == selectors.length-1){
if (!(/[#.]/g).test(selectors[i])) { //If it is an HTML tag
return el .getElementsByTagName(selectors[i]);
}
else { //If it is an ID or class attribute
return (this.IDLabel(selectors[i])) ? this.$(val) : this .getElementsByClassName(el,"*",val);
}
}
else{ //If there are more than two levels of selectorStr, store the reference of the current node in the parent attribute
if ( !(/[#.]/g).test(selectors[i])) { //If it is an HTML tag
this.parent = el.getElementsByTagName(selectors[i])[0];
}
else { //If it is an ID or class attribute
this.parent = ((/#/gi).test(selectors[i])) ? this.$(val) : el;
}
}
}
},
$: function(id){ //Reference used to get the specified ID
return document.getElementById(id);
},
IDLabel: function(selector){ //Determine whether it is an ID attribute
return ((/#/gi).test(selector)) ? true : false;
},
classLabel: function(selector ){ //Determine whether it is a class attribute
return ((/./gi).test(selector)) ? true : false;
},
replaceStr:function(a){ //Replace "#" and "." dots are used to obtain the node reference of the specified ID
return a.replace("#","").replace(".","");
},
getElementsByClassName: function(el, tag, classname){ //Get the reference of the element containing the class attribute value through the class attribute value
var elem = el || document;
if (!classname)
return;
tag = tag || "*";
var allTagsDom = ((tag == "*") && (elem.all)) ? elem.all : elem.getElementsByTagName(tag);
classname = classname.replace(/-/g, "\-");
var regex = new RegExp("(^|\s*)" classname "(\s*|$)");
var matchElements = new Array();
var element;
for (var i = 0; i < allTagsDom.length; i ) {
element = allTagsDom[i];
if (regex.test(element.className)) { //Detect class names according to regular rules
matchElements.push(element);
}
}
return matchElements;
}
}
//Call method: cssQuery.select(selectorString); selectorString like this: "#p #b .em",
//Can receive a combination of HTML tags, ID, and class, and return the specified selectorString References

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

JSON (JavaScriptObjectNotation) is a lightweight data exchange format that has become a common format for data exchange between web applications. PHP's json_encode() function can convert an array or object into a JSON string. This article will introduce how to use PHP's json_encode() function, including syntax, parameters, return values, and specific examples. Syntax The syntax of the json_encode() function is as follows: st

Wedge We know that objects are created in two main ways, one is through Python/CAPI, and the other is by calling a type object. For instance objects of built-in types, both methods are supported. For example, lists can be created through [] or list(). The former is Python/CAPI and the latter is a calling type object. But for instance objects of custom classes, we can only create them by calling type objects. If an object can be called, then the object is callable, otherwise it is not callable. Determining whether an object is callable depends on whether a method is defined in its corresponding type object. like

The Request object in PHP is an object used to handle HTTP requests sent by the client to the server. Through the Request object, we can obtain the client's request information, such as request method, request header information, request parameters, etc., so as to process and respond to the request. In PHP, you can use global variables such as $_REQUEST, $_GET, $_POST, etc. to obtain requested information, but these variables are not objects, but arrays. In order to process request information more flexibly and conveniently, you can

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

Use Python's __contains__() function to define the containment operation of an object. Python is a concise and powerful programming language that provides many powerful features to handle various types of data. One of them is to implement the containment operation of objects by defining the __contains__() function. This article will introduce how to use the __contains__() function to define the containment operation of an object, and give some sample code. The __contains__() function is Pytho

Title: Using Python's __le__() function to define a less than or equal comparison of two objects In Python, we can define comparison operations between objects by using special methods. One of them is the __le__() function, which is used to define less than or equal comparisons. The __le__() function is a magic method in Python and is a special function used to implement the "less than or equal" operation. When we compare two objects using the less than or equal operator (<=), Python

In PHP, an array is an ordered sequence, and elements are accessed by index; an object is an entity with properties and methods, created through the new keyword. Array access is via index, object access is via properties/methods. Array values are passed and object references are passed.

In C++, there are three points to note when a function returns an object: The life cycle of the object is managed by the caller to prevent memory leaks. Avoid dangling pointers and ensure the object remains valid after the function returns by dynamically allocating memory or returning the object itself. The compiler may optimize copy generation of the returned object to improve performance, but if the object is passed by value semantics, no copy generation is required.
