jquery 1.9.0 live function?

后端 未结 4 1199
迷失自我
迷失自我 2020-12-06 05:56

There is no live() function in jquery 1.9.0, but jquery.unobtrusive.ajax.js is already use this function.

Should I us

相关标签:
4条回答
  • 2020-12-06 06:15

    Depreciated as of 1.7 and removed as of 1.9. Use on() instead.

    http://api.jquery.com/on/

    $("#myButton").on("click", function(){
        alert("Clicked");
    });
    

    Lots of good info here:

    http://www.elijahmanor.com/2012/02/differences-between-jquery-bind-vs-live.html

    As for Unobtrusive Ajax, you will need to include a version of jQuery prior to v1.9 where live() still exists.

    If you are referencing the MS CDN,

    http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.js http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.min.js

    then it does not appear that these directly reference jQuery. Simply include the 1.8 version in your code instead of the 1.9 version.

    0 讨论(0)
  • 2020-12-06 06:15

    jquery.migate adds back in the legacy function. This means that jquery.unobtrusive.ajax.js functions as expected.

    Reference the jquery.migrate library as per the official blog and there is a nuget pacakge too but obviously you'll need to update your template/layout views.

    http://blog.jquery.com/2013/01/31/jquery-migrate-1-1-0-released/

    http://nuget.org/packages/jQuery.Migrate/

    Javascript console does highlight the issue ...

    JQMIGRATE: Logging is active JQMIGRATE: jQuery.fn.live() is deprecated JQMIGRATE: jQuery.fn.andSelf() replaced by jQuery.fn.addBack() JQMIGRATE: jQuery.clean() is deprecated

    0 讨论(0)
  • 2020-12-06 06:22

    live() has been deprecated in the latest jQuery versions but Microsoft mantains updated unobtrusive scripts as NuGet packages that overwrite the default ones:

    • Microsoft.JQuery.Unobtrusive.Ajax
    • Microsoft.JQuery.Unobtrusive.Validation
    0 讨论(0)
  • 2020-12-06 06:26

    .live() has been replaced with the event delegation syntax of .on():

    $('#parent').on('click', '.child', function() {
      ...
    });
    

    #parent should exist when you call your selector, so if your element is top-level, use document as the parent.

    0 讨论(0)
提交回复
热议问题