栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何终止JavaScript中的脚本?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何终止JavaScript中的脚本?

等同于PHP的Javascript

die
。顺便说一句,它只是调用
exit()

function exit( status ) {    // http://kevin.vanzonneveld.net    // +   original by: Brett Zamir (http://brettz9.blogspot.com)    // +      input by: Paul    // +   bugfixed by: Hyam Singer (http://www.impact-computing.com/)    // +   improved by: Philip Peterson    // +   bugfixed by: Brett Zamir (http://brettz9.blogspot.com)    // %        note 1: Should be considered expirimental. Please comment on this function.    // *     example 1: exit();    // *     returns 1: null    var i;    if (typeof status === 'string') {        alert(status);    }    window.addEventListener('error', function (e) {e.preventDefault();e.stopPropagation();}, false);    var handlers = [        'copy', 'cut', 'paste',        'beforeunload', 'blur', 'change', 'click', 'contextmenu', 'dblclick', 'focus', 'keydown', 'keypress', 'keyup', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'resize', 'scroll',        'DOMNodeInserted', 'DOMNodeRemoved', 'DOMNodeRemovedFromdocument', 'DOMNodeInsertedIntodocument', 'DOMAttrModified', 'DOMCharacterDataModified', 'DOMElementNameChanged', 'DOMAttributeNameChanged', 'DOMActivate', 'DOMFocusIn', 'DOMFocusOut', 'online', 'offline', 'textInput',        'abort', 'close', 'dragdrop', 'load', 'paint', 'reset', 'select', 'submit', 'unload'    ];    function stopPropagation (e) {        e.stopPropagation();        // e.preventDefault(); // Stop for the form controls, etc., too?    }    for (i=0; i < handlers.length; i++) {        window.addEventListener(handlers[i], function (e) {stopPropagation(e);}, true);    }    if (window.stop) {        window.stop();    }    throw '';}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/575225.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号