Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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 实时错误_Javascript_Jquery - Fatal编程技术网

Javascript 实时错误

Javascript 实时错误,javascript,jquery,Javascript,Jquery,升级jquery后,我得到一个错误。 当我执行以下javascript时,我得到错误ther$(…)。live不是一个函数。我怎样才能解决这个问题 $(function(){ $('input[type=text]').live('focus',function(e){ $(this).get(0).focus(); $(this).get(0).select(); //$(this).val(''); }); $('.blogImageSmall').bind('

升级jquery后,我得到一个错误。 当我执行以下javascript时,我得到错误ther$(…)。live不是一个函数。我怎样才能解决这个问题

$(function(){
$('input[type=text]').live('focus',function(e){

    $(this).get(0).focus();
    $(this).get(0).select();

    //$(this).val('');
});

$('.blogImageSmall').bind('click', function(e){
    var oldHref = $('#blogImageLink').attr('href');
    var oldSrc = $('#blogImageLink').find('img').attr('src');

    $('#blogImageLink').attr('href', $(this).attr('href'));
    $('#blogImageLink').find('img').attr('src', $(this).attr('rel'));

    $(this).attr('href', oldHref);
    $(this).attr('rel', oldSrc); // .replace('150_', '35_')
    $(this).find('img').attr('src', oldSrc.replace('150_', '35_'));

    e.preventDefault();
    return false;
});

// preload image:
var img = new Image(16,11);
img.src = '/images/ajax-loader.gif';
});
.live()
API早就被弃用了。你可以得到

$("some selector").live("event", function() { ... })
把它改写成

$(document).on("event", "some selector", function() { ... })
该转换不需要更改回调(事件处理程序)函数,但如果jQuery代码足够旧,则函数中可能存在其他错误

.live()
的问题在于,构建jQuery对象的初始调用几乎完全是白费力气。就是在

$("some selector").live( ... )

在调用
.live()
之前,jQuery当然会执行DOM搜索“someselector”。在此之后,
.live()
将不关注库在DOM中找到的内容,只使用选择器字符串本身来建立委托事件处理程序(这部分行为本质上就是
.on()
所做的)。新的API允许您执行与允许的
.live()
相同的操作,而且它实际上更灵活,因为您可以控制在DOM中放置委派事件处理程序的位置。(通常,
文档
很好,但有时您可能需要更细粒度的控制。)

而不是“实时”使用“打开”“live”是不推荐使用的jquery 1.9版监听器。我想
。live()
是不推荐使用的,他们在jquery 1.9中删除了它。您可以改用
.on()