SoFunction
Updated on 2025-04-11

js code set (friends who learn js can read it)

/**
* @author Super Sha
* QQ:770104121
* E-Mail:supei_shafeng@
* publish date: 2009-3-27
* All Rights Reserved
*/

var JsHelper={}; //Declare a JsHelper root namespace
= {}; //Declare the DOM namespace in the JsHelper directory
={}; //Declare the Event event namespace in the JsHelper directory
={}; //Declare the browser-related function Browser namespace in the JsHelper directory
={}; //Declare the function namespace related to Ajax in the Jselper directory
={}; //Declare the String-related namespace in the JsHelper directory

/*
* $() can enter multiple parameters and will return an array of objects.
*/
var $=function(){ //Simplified version of $ method
var elements=new Array();
if(==0){ //If the parameter is empty, return the document element
return document;
}
for (var i = 0; i < ; i++)
{
var element = arguments[i];
if (typeof element == string )
{
element = (element);
}
if ( == 1)
{
return element;
}
(element);
}
return elements;
}
.$=function()
{
var elements=new Array();
for (var i = 0; i < ; i++)
{
var element = arguments[i];
if (typeof element == string )
{
element = (element);
}
if ( == 1)
{
return element;
}
(element);
}
return elements;
}
/*
* $Value() can enter multiple parameters and will return a Value array that gets the object.
*/
=function()
{
var values=new Array();
for (var i = 0; i < ; i++)
{
var element = arguments[i];
if (typeof(element) == string )
{
var v=(element).value;
}
if(==1)
{
return v;
}
(v);
}
return values;
}
/*
MakeArray generates an array for input parameters, if the parameter is empty, it returns "undefined", otherwise it returns the array
*/
=function()
{
var values=new Array();
if(>0){
for (var i = 0; i < ; i++)
{
var element=arguments[i];
if(typeof element == "string")
{
(element);
}
}
}
else
{
return "undefined";
}
return values;
}
/*
* Declare a StringBuilder class to handle the performance of connection strings
*/
={
_strs:new Array(),
append: function(str){ //Add string to attribute_strs
this._strs.push(str);
return this;
},
toString:function(){
if ( != 0) {
return this._strs.join(arguments[0]); //Return the string after attribute _strs is combined, accepting an optional parameter for join parameters
}else{
return this._strs.join("");
}
}
};

/*
* $TagName() Enter a parameter and will return an array that gets the Elements TagNeme object.
*/
=function()
{
var element=arguments[0];
if(typeof element== string )
{
var tagname=(element);
}
return tagname;
}

//============================================================
/*
* label:HTML Label ID
* Only applicable with responseText
* Only applicable to GET methods
*/
var _xmlhttp;//Declare global XMLHttpRequest object instance
function Ajax(method, url, label){
= method;
= url;
try {
_xmlhttp = new ActiveXObject("");
}
catch (e) {
try {
_xmlhttp = new ActiveXObject("");
}
catch (s) {
_xmlhttp = new XMLHttpRequest();
}
}
= function(){
_xmlhttp.onreadystatechange = ;
_xmlhttp.open(, , true)
_xmlhttp.send(null);
}
= function(){
if (_xmlhttp.readyState == 4) {
if (_xmlhttp.status == 200) {
$(label).innerHTML = _xmlhttp.responseText;
}
}
}
();
}
//================================================

/*
* Determine browser type
*/
var ua = ();
if () {
= (/msie ([\d.]+)/)[1];
}
else if () {
= (/firefox\/([\d.]+)/)[1];
}
else if ( && !) {
= (/chrome\/([\d.]+)/)[1];
}
else if () {
= (/opera.([\d.]+)/)[1];
}
else if () {
= (/version\/([\d.]+)/)[1];
}
/*
* Declare an instance of XMLHttpRequest object and return the instance
*/
=function()
{
var xmlhttp=null;
try
{
xmlhttp=new XMLHttpRequest();
}
catch(trymicrosoft){
try {
xmlhttp = new ActiveXObject("");
}
catch(othermicrosoft){
xmlhttp=new ActiveXObject("");
}
}
return xmlhttp;
}

/*
* A general AddEventListener function, obj is the DOM element
*/
=function(labelID,eventMode,fn)
{
var obj=.$(labelID);
if (typeof != undefined ) {
(eventMode, fn, false);
}
else
if (typeof != undefined ) {
(eventMode, fn, false);
}
else
if (typeof != undefined ) {
("on"+eventMode, fn);
}
else {
return false;
}
return true;
}

/*
*Contains a Douglas Crockford extension to the function method. The copyright of the following three functions belongs to Douglas Crockford. This is hereby declared
*/
= function (name, func) {
[name] = func;
return this;
};
( inherits , function (parent) {
var d = {}, p = ( = new parent());
( base , function uber(name) {
if (!(name in d)) {
d[name] = 0;
}
var f, r, t = d[name], v = ;
if (t) {
while (t) {
v = ;
t -= 1;
}
f = v[name];
} else {
f = p[name];
if (f == this[name]) {
f = v[name];
}
}
d[name] += 1;
r = (this, (arguments, [1]));
d[name] -= 1;
return r;
});
return this;
});
( swiss , function (parent) {
for (var i = 1; i < ; i += 1) {
var name = arguments[i];
[name] = [name];
}
return this;
});

/*
* A solution to solve the problem that IE does not support HTMLElement
*/
var DOMElement ={
extend: function(name,fn)
{
if(!)
{
eval("." + name + " = fn");
}
else
{
var _createElement = ;
= function(tag)
{
var _elem = _createElement(tag);
eval("_elem." + name + " = fn");
return _elem;
}
var _getElementById = ;
= function(id)
{
var _elem = _getElementById(id);
eval("_elem." + name + " = fn");
return _elem;
}
var _getElementsByTagName = ;
= function(tag)
{
var _arr = _getElementsByTagName(tag);
for(var _elem=0;_elem<_arr.length;_elem++)
eval("_arr[_elem]." + name + " = fn");
return _arr;
}
}
}
};
/*
* The following is a few DOM query functions imitated by John Resig, the father of jQuery, and the ability to connect them
*/
("previous",function(){ // similar to previousSibling DOM Function
var elem=this;
do{
elem=;
}while(elem&&!=1);
return elem;
});

("next",function(){ //similar to nextSibling DOm Function
var elem=this;
do{
elem=;
}while(elem&&!=1);
return elem;
});
("first",function(num){ //similar to firstChild DOM Function, same as parent
var elem=this;
num=num||1;
for (var i = 0; i < num; i++) {
elem = ;
}
return (elem && !=1 ? next(elem):elem);
});
("last",function(num){ //similar to lastChild DOM Function, same as parent
var elem=this;
num=num||1;
for (var i = 0; i < num; i++) {
elem = ;
}
return (elem && !=1 ? prev(elem):elem);
});
("parent",function(num){ //You can return several num levels parentNodes, such as: parent(2) is equivalent to ().parent();
var elem=this;
num=num ||1;
for (var i = 0; i < num; i++) {
if (elem != null) {
elem = ;
}
}
return elem;
});
("hasChilds",function(){ //There are children when judging that there are
if(this!=null && ()){
return true;
}
else{
return false;
}
});

("text",function(){ //Get the text in the tag. If the parameter is not zero, you can set the text version in the tag, which is also suitable for input tags.
try{ //Solve the solution that Firefox does not support InnerText
.__defineGetter__("innerText",function(){
var anyString = "";
var childS = ;
for(var i=0; i<; i++){
if (childS[i].nodeType == 1) {
anyString += childS[i].tagName == "BR" ? "n : childS[i].innerText;
}
else if(childS[i].nodeType == 3) {
anyString += childS[i].nodeValue;
}
}
return anyString;
});
}
catch(e){}
if ( == 1) {
if () {
= arguments[0];
}
else {
= arguments[0];
}
}
else {
return || ;
}
});
("html",function(){ //Get the innerHTML of the element. If the parameter is not zero, you can set the text and child nodes in the element.
if(==0){
return ;
}
else if(==1)
{
=arguments[0];
}
});

/*
* The following is the className operation
*/
("getClassName",function(){ //Return element className
if(this!=null&&==1){
return (/\s+/, ).split( );
}
return null;
});
("hasClassName",function(){ //Judge whether there is a class class
if(this!=null&&==1){
var classes=();
for(var i=0;i<;i++){
if(arguments[0]==classes[i]) return true;
}
}else{
return false;
}
});

("addClass",function(){ //Add a class to an element, you can add multiple classes at once
if(this!=null&&==1){
for (var i = 0; i < ; i++) {
+= ( ? : ) + arguments[i];
}
return this;
}
return null;
});
("removeClass",function(){ //Delete the class, if there are no parameters, delete all classes
if (this != null && == 1) {
if ( == 0) {
= "";
}
else if(!=0) {
var classes=();
for (var i = 0; i < ; i++) {
for (var j = 0; j < ; j++) {
if (arguments[i]==classes[j]) {
classes = (" ").replace(arguments[i], ).split(" ");
}
}
}
=(" ");
}
return this;
}
return null;
});
JsHelper.__toggleflag=false; //Add a judgment switch
("toggleClass",function(classname){ //The function called by the two clicks is different
if(this!=null && ==1){
=function(){
if(JsHelper.__toggleflag==false){
(classname);
JsHelper.__toggleflag = true;
}else if (JsHelper.__toggleflag == true) {
(classname);
JsHelper.__toggleflag = false;
}
}
}
});
/*
* Add click method to each object, similar to how to use the click method of jQuery
*/
("click",function(){
if(this!=null && ==1){
if(==0){
alert("you have done nothing when you clicked.");
}else{
=arguments[0];
}
}
});

/*
* Extend the hover method to each object, this method accepts two functions as parameters
*/
("hover",function(){
if(this!=null && ==1){
if(!=2){
alert("Require two function to be param.");
}else{
=arguments[0];
=arguments[1];
}
}
});
/*
* Function that adds events to each element
*/
("addEvent",function(eventtype,fn){
if(){
("on"+eventtype,fn);
}else{
(eventtype,fn,false);
}
});
/*
* Extend css method to each element, accept an attribute and attribute value as parameters
*/
("css",function(){
if(this!=null && ==1){
if(!=2){
alert("Require two function to be param.");
}else{
[arguments[0]]=arguments[1]; //Set the value of the relevant style attribute
return this;
}
}
return null;
});
/*
* //Find and return all elements of a certain class, name is className, type is HTML tag type
*/
var hasClass = function(name,type){
var r = new Array();
//var re = new RegExp(name,"g");
var e=(type||"*");
for(var i=0;i<;i++){
var classes=e[i].getClassName();
for (var j = 0; j < ; j++) {
if (name== classes[j]) {
(e[i]);
}
}
}
return r;
}
/*
* Returns a collection of references to a specific child element of an element. If no element calls the method, the default is document.
*/
("find",function(){
var elem=this||document;
var r=new Array();
if(elem!=null && (==1||==9)){
var e=(arguments[0]);
for(var i=0;i<;i++){
(e[i]);
}
return r;
}
return null;
});