Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么在刷新页面之前,jQuery.prototype($.fn)修改在Internet Explorer 11的事件处理程序中不起作用?_Javascript_Jquery_Internet Explorer - Fatal编程技术网

Javascript 为什么在刷新页面之前,jQuery.prototype($.fn)修改在Internet Explorer 11的事件处理程序中不起作用?

Javascript 为什么在刷新页面之前,jQuery.prototype($.fn)修改在Internet Explorer 11的事件处理程序中不起作用?,javascript,jquery,internet-explorer,Javascript,Jquery,Internet Explorer,我遇到了一些添加到jQuery.prototype($.fn)中的jQuery插件的问题,这些插件在页面刷新后才能在InternetExplorer11中工作。我相信以下说明了问题的根源: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>foobar</title&g

我遇到了一些添加到jQuery.prototype($.fn)中的jQuery插件的问题,这些插件在页面刷新后才能在InternetExplorer11中工作。我相信以下说明了问题的根源:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>foobar</title>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(function(){
    var outside_jQuery = jQuery();
    jQuery.prototype.foo = function(){};

    $('pre').append('foo in outside_jQuery on load? '
        + ('foo' in outside_jQuery).toString());

    $('input').on('click', function(){
        $('pre').append('\nfoo in outside_jQuery on click? '
            + ('foo' in outside_jQuery).toString());
        $('pre').append('\nfoo in jQuery() on click? '
            + ('foo' in jQuery()).toString());
    });
});
</script>
</head>
<body>
<input type="button" value="foo?" />
<pre></pre>
</body>
</html>

福巴
$(函数(){
var out_jQuery=jQuery();
jQuery.prototype.foo=function(){};
$('pre').append('foo-in-out\u jQuery-on-load?'
+('foo'在outsidejquery.toString()中);
$('input')。在('click',function()上{
$('pre').append('\n单击时在外部查询中查找?'
+('foo'在outsidejquery.toString()中);
$('pre').append('\nFo在jQuery()中单击?'
+(jQuery()中的“foo”).toString();
});
});
在Firefox 26中,单击按钮后,输出如下所示:

foo在外部\u jQuery加载?正确
点击外部查询中的foo?正确
单击jQuery()中的foo?真的

在Internet Explorer 11中,单击按钮后,输出如下:

foo在外部\u jQuery加载?正确
点击外部查询中的foo?正确
单击jQuery()中的foo?假的

但是,在刷新页面一次后,它会按预期工作


在页面刷新之前,对jQuery.prototype的更改似乎不会反映在事件处理程序中创建的新jQuery对象中。为什么?

为什么您不使用
jQuery.fn
?我相信,但为了问这个问题,原型听起来比fn更有意义。很抱歉我的垃圾评论,但因为
ie
是一个糟糕的、不一致的浏览器…?它是一个别名,但是这是构建jQuery插件的标准方法。那么您认为将标题和代码从jQuery.prototype更改为jQuery.fn是否有助于其他人理解这个问题?