`
123003473
  • 浏览: 1043471 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

window.error(fn)

阅读更多
在每一个匹配元素的error事件中绑定一个处理函数。
      对于error事件,没有一个公众的标准。在大多数浏览器中,当页面的JavaScript发生错误时,window对象会触发error事件;当图像的src属性无效时,比如文件不存在或者图像数据错误时,也会触发图像对象的error事件。

如果异常是由window对象抛出,事件处理函数将会被传入三个参数:

1. 描述事件的信息 ("varName is not defined", "missing operator in e­xpression", 等等.),

2. 包含错误的文档的完整URL

3. 异常发生的行数

如果事件处理函数返回true,则表示事件已经被处理,浏览器将认为没有异常。

返回值:jQuery
      参数:
      fn(Function) : 在每一个匹配元素的error事件中绑定的处理函数。

      示例:
      在服务器端记录JavaScript错误日志:


$(window).error(function(msg, url, line){
  jQuery.post("js_error_log.php", { msg: msg, url: url, line: line });
}); 


      隐藏JavaScript错误:

      jQuery 代码:
      
 程序代码
$(window).error(function(){
  return true;
}); 


      给你IE的用户隐藏无效的图像:

      jQuery 代码:
      
 程序代码
$("img").error(function(){
  $(this).hide();
}); 



分享到:
评论

相关推荐

    jQuery 1.5 API 中文版

    $.ajaxError( fn( event, XHR, options, thrownError ) ) $.ajaxSend( fn( event, XHR, options ) ) $.ajaxStart( fn( ) ) $.ajaxStop( fn( ) ) $.ajaxSuccess( fn(event, XHR, options) ) Miscellaneous str....

    图形jquery.gvChart-1.0.1.min.js

    $.print = $.fn.print = function () { // Print a given set of elements var options, $this, self = this; // console.log("Printing", this, arguments); if (self instanceof $) { // Get the node if it...

    jquery1.11.0手册

    jQuery.fn.extend(object) jQuery.extend(object) 多库共存 jQuery.noConflict([ex]) 属性 属性 attr(name|pro|key,val|fn) removeAttr(name) prop(n|p|k,v|f) removeProp(name) CSS 类 addClass(class...

    simplewebrtc.js webrtc网页视频开发帮助工具

    fn.apply(this, arguments); } this.on(event, on); return this; }; // Unbinds an entire group WildEmitter.prototype.releaseGroup = function (groupName) { var item, i, len, handlers; for (item in...

    jQuery 1.6.3正式版发布

    #9794:jQuery.fn.data() correctly handle access to arbitrary data property values #10016:Cannot retrieve “false-y” values under key names with dashes using jQuery.data method #10080:unload from ...

    au3反编译源码

    To copy text or to enlarge the log window double click on it. Supported Obfuscators: 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.14 [June 16, 2007]' , 'Jos van der Zande AutoIt3 Source ...

    新浪推荐浮动广告

    throw new Error("this method can only execute in IE"); } } function $addEL(n,e,l,b){ if ($IE){ if (n["$__listener_"+e]==null){ var lst=function (e){ ...

    Sortable前端框架

    # Sortable Sortable is a <s>minimalist</s> JavaScript library for reorderable drag-and-drop lists. ... ## Features ... * Can drag from one list to another or within the same list * CSS animation when ...

    jqzoom放大镜插件.zip

    $.fn.jqzoom = function(options) { var settings = { zoomType: 'standard', //standard/reverse/innerzoom zoomWidth: 400, //zoomed width default width zoomHeight: 400, //zoomed div default width ...

    jQuery1.3API参考文档中文版

    + ajax的error回调的第二个参数可能值"timeout", "error", "notmodified" 和 "parsererror" + ajax参数xhr * animate 的duration为0的问题 * show, hide, toggle, slideDown, slideUp, slideToggle 在jQuery 1.3中,...

    jQuery 1.3 API 参考文档中文版 html

    + ajax的error回调的第二个参数可能值"timeout", "error", "notmodified" 和 "parsererror" + ajax参数xhr * animate 的duration为0的问题 * show, hide, toggle, slideDown, slideUp, slideToggle 在jQuery 1.3中,...

    jquery-fetch:围绕jQuery的基于承诺的包装器,可在get和post之间动态选择,并实现验证和错误报告

    jQuery的获取 围绕jQuery的基于约定的包装器,可在get... fetch = { fn_text : "There has been an error:" , do_globals : true } ; </ script > 如果do_globals为true,则它将实用程序功能也导出到window中:

    The Art of Assembly Language Programming

    Some Final Comments on the MOV Instructions <br>4.9 Laboratory ...Window 4.9.5.3 The Memory Window 4.9.5.4 The Register Window 4.9.5.5 The Command Window 4.9.5.6 The Output Menu Item ...

    Bochs - The cross platform IA-32 (x86) emulator

    [3108422] Timing window in NE2K emulation [3084390] Bochs won't load floppy plugin right on startup [3043174] Docbook use of '_' build failure [3085140] Ia_arpl_Ew_Rw definition of error [3078995...

    一个完美的视屏播放器

    <html><title>ERROR代码测试</title><body> //ServerName NetShowServer = "" ; //Path //var mPath = NetShowServer + "/entercp/mnet/"; var mPath = NetShowServer + ""; var bgImage = "bg.gif"; var ...

    failsafe-rs:Rust 的断路器实现

    特征同时使用Fn() -> Result和Future (通过默认的futures-support功能可选)。 退避策略: constant 、 exponential 、 equal_jittered 、 full_jittered 故障检测策略: consecutive_failures , success_rate_...

    crow:一个简单的像素完美2D渲染引擎

    乌鸦 此板条箱仍处于开发初期,高度不稳定且功能尚未完善 一个简单且相当有效的基于像素的2D图形库... window :: WindowBuilder, }, Context, DrawConfig, Texture, }; fn main () -> Result <(), crow::Error> {

    计算机网络第六版答案

    22. Five generic tasks are error control, flow control, segmentation and reassembly, multiplexing, and connection setup. Yes, these tasks can be duplicated at different layers. For example, error ...

Global site tag (gtag.js) - Google Analytics