search
HomeWeb Front-endJS TutorialDetailed explanation of the use of practical functions in parsing javascript_javascript skills

Copy code The code is as follows:

function addBookMark(url, title){
//将网页添加到收藏addBookMark(window.location,document.title)
    if(document.all){
      window.external.addFavorite(url,title);
    }else if (window.sidebar){
      window.sidebar.addPanel(title,url,'');
    }else{
      alert('添加失败');
    }
}  


function setHomepage(obj,url) {
// setHome(this, window.location)
    try {  
        obj.style.behavior = 'url(#default#homepage)';  
        obj.setHomePage(url);  
    } catch (e) {  
        if (window.netscape) {  
            try {  
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            } catch (e) {  
                alert('此操作被浏览器拒绝!\n请在浏览器地址栏输入"about:config"并回车 然后将 [signed.applets.codebase_principal_support]的值设置为"true",双击即可。');  
            }  
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);  
            prefs.setCharPref('browser.startup.homepage', vrl);  
        }  
    }  
}  

function boxMove(box){
//可移动的层
    var w = box.scrollWidth,h = box.scrollHeight;
    var iWidth = document.documentElement.clientWidth;
    var iHeight = document.documentElement.clientHeight;    
    var moveX = 0,moveY = 0,moveTop = 0,moveLeft = 0,moveable = false;
    box.onmousedown = function(e){   
    moveable = true;    
    e = window.event?window.event:e;
    moveX = e.clientX-box.offsetLeft;       
    moveY = e.clientY-box.offsetTop;
    box.style.zIndex++;
    }
    document.onmousemove = function(e){
        if(moveable){
            e = window.event?window.event:e;       
            var x = e.clientX - moveX;
            var y = e.clientY - moveY;
            if ( x > 0 &&( x + w 0 && (y + h                 box.style.left = x + "px";
                box.style.top = y + "px";
                box.style.margin = "auto";
            }
        }
    }
    document.onmouseup = function (){moveable = false;};
}

function getHtmlRoot(){
/*获得html文档的根元素*/
    if(document.compatMode.toLowerCase()=="css1compat"){
        htmlRoot = document.documentElement;
    }else{
        htmlRoot = document.body;
    }
    return htmlRoot;
}


function showWindow(boxId, closeId, showBg){//弹窗
    htmlRoot = getHtmlRoot();
    box = document.getElementById(boxId);
    boxId = '#' + boxId;
    closeId = '#' + closeId;
    showBox = $(boxId);
    showBox.show();
    z_index = 20;
    moveLeft =  (htmlRoot.clientWidth- box.clientWidth)/2 + htmlRoot.scrollLeft +'px';
    moveTop = (htmlRoot.clientHeight - box.clientHeight)/2 + htmlRoot.scrollTop;+'px';
    showBox.css({position:'absolute', left:moveLeft,zIndex:z_index, top:moveTop});

    boxMove(box);

    if(showBg){
        objMask = document.createElement("div");
        objMask.className = "BoxMask";
        htmlRoot.appendChild(objMask);
        objMask.style.cssText += 'position:absolute;top:0; left:0;filter:Alpha(Opacity=50);opacity:0.5;background:#AAA;';

        objMask.style.zIndex = z_index -1;
        objMask.style.width =  htmlRoot.clientWidth + 'px';
        objMask.style.height = htmlRoot.scrollHeight + htmlRoot.scrollTop + 'px';
    }

    $(closeId).click(function(){
        showBox.hide();
        mybg.style.display = "none";
    });
    $('.closeBtn').click = function(){
        showBox.hide();
        mybg.style.display = "none";   
    };

}

function getFormQuery(formId){
/*生成查询字串*/
    formObj = document.getElementById(formId);
       var i, queryString = "", and = "", itemValue;
       for(i = 0; i             var item = formObj[i];
              if ( item.name!='' ){
                     if(item.type == 'select-one'){
                         itemValue = item.options[item.selectedIndex].value;
                     }else if ( item.type=='checkbox' || item.type=='radio'){
                         if ( item.checked == false ){ continue; }
                         itemValue = item.value;
                     }else if ( item.type == 'button' || item.type == 'submit' || item.type == 'reset' || item.type == 'image'){
                         continue;
                     }else{
                          itemValue = item.value;
                     }
                   //  itemValue = escape(itemValue);
                     queryString += and + item.name + '=' + itemValue;
                     and="&";
                   //queryString += and + encodeURIComponent(item.name) + '=' +encodeURIComponent( itemValue);
              }
       }
       return queryString;
}

//定义js错误处理函数
onerror = errHandle;
function errHandle(msg,url,line){
    var txt=""
    txt = "本页中有错误! \n"
    txt += "错误: "+ msg +"\n"
    txt += "地址: " + url + "\n"
    txt += "行数: " + line + "\n\n"
    alert(txt);
    return false;
}


function setAutoWidth(id,width,size){
//最小或最大宽度
    var obj = document.getElementById(id);
    if(size=='max'){
        obj.style.width = (obj.clientWidth > width) ? width + "px" : "auto";
    }else{
        obj.style.width = (obj.clientWidth     }
}

function fontScroll(id){
/*向左滚动的文字 */
    var obj = document.getElementById(id);
    var text = obj.innerHTML;
    var first = text.charAt(0);
    var left = text.substring(1, text.length);
    obj.inerHTML = left + first;
    //这个写函数之外 setInterval('fontScroll(id)', 500);
}

function bubbleSort(arr){
/*バブルソートメソッド*/
var signed = false // 転置符号を false に初期化します
for(var i=0; i for(varj=0; j if(arr[j]> arr[j 1]){
vartemp = arr[j]
arr[j]= arr[j 1]
arr[j 1]= temp
sign= true // 現在の円の比較に転置がある場合、置換マークは true
}
}
if(sign)// 現在のサークルに置換があったかどうかを判断します...
sign= false // 置換があった場合、 retry 置換ビットは false としてマークされます
else
Break// そうでない場合は終了します
}
return arr;
}

function getCooperative(evt){
/*カーソルの座標を取得*/
var x = evt.clientX;
var y = evt.clientY;
document.getElementById(' show' ).innerHTML = x ' &' y;
}

function checkEmail(email){
/*セミコロン (;) で区切って複数の電子メール形式を検出します*/
if(email != null){
if(email.indexOf(" ;", 0) == -1){ //indexOf(検索済み, 開始位置) は、ソース文字列内で特定の文字列が最初に出現する位置を返します。失敗した場合は、-1
が返されます。 if(!isEmail(email )) {
alert("単一メールの形式が間違っています。再入力してください!"); > }else{
var emailArr = email.split(";");//split (分割されたセグメント、配列の合計長) 文字列は文字列に分割されます array
var i, iMax = emailArr.length;
for(i = 0; i if(emailArr[i] != null || emailArr != ""){
if(!isEmail(emailArr[i]) ){
alert("複数のメール形式の 1 つが間違っています。入力する前にもう一度確認してください!") ;
document.getElementById("email").focus();
return false ;
}
}
}
}
}
}
function isEmail(str){
var reg = /^(w) (.w )*@(w) ((.w ) )$/;
return reg.test(str);//test (テストされた文字列) は、文字列が特定のパターンに一致するかどうかを検出します。
}
}


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Javascript Data Types : Is there any difference between Browser and NodeJs?Javascript Data Types : Is there any difference between Browser and NodeJs?May 14, 2025 am 12:15 AM

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScript Comments: A Guide to Using // and /* */JavaScript Comments: A Guide to Using // and /* */May 13, 2025 pm 03:49 PM

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.