jQuery中live()使用报错,TypeError: $(...).live is not a function

原地址: https://blog.csdn.net/sdfdyubo/article/details/59536781

1、使用

(1)原写法

/*为选项卡绑定右键*/
    $(".tabs li").live(‘contextmenu‘, function (e) {
        /*选中当前触发事件的选项卡 */
        var subtitle = $(this).text();
        $(‘#mainTab‘).tabs(‘select‘, subtitle);
        //显示快捷菜单
        $(‘#tab_menu‘).menu(‘show‘, {
            left: e.pageX,
            top: e.pageY
        });
        return false;
    });

(2)调整后的写法

/*为选项卡绑定右键*/
    $(".tabs").on("contextmenu", "li", function (e) {
        /*选中当前触发事件的选项卡 */
        var subtitle = $(this).text();
        $(‘#mainTab‘).tabs(‘select‘, subtitle);
        //显示快捷菜单
        $(‘#tab_menu‘).menu(‘show‘, {
            left: e.pageX,
            top: e.pageY
        });
        return false;
    });

2、说明

jquery中的live()方法在jquery1.9及以上的版本中已被废弃了,如果使用,会抛出TypeError: $(...).live is not a function错误。

解决方法:

之前的用法:

.live(events, function)

新方法:

.on(eventType, selector, function)

若selector不需要,可传入null

例子1:

之前:

$(‘#mainmenu a‘).live(‘click‘, function)

之后:

$(‘#mainmenu‘).on(‘click‘, ‘a‘, function)

例子2:

之前:

$(‘.myButton‘).live(‘click‘, function)

之后(应使用距离myButton最近的节点):

$(‘#parentElement‘).on(‘click‘, ‘.myButton’, function)

若不知最近的节点,可使用如下的方法:

$(‘body‘).on(‘click‘, ‘.myButton’, function)

原文地址:https://www.cnblogs.com/masonblog/p/9533022.html

时间: 2024-08-28 15:29:48

jQuery中live()使用报错,TypeError: $(...).live is not a function的相关文章

Android中editText使用报错

在activity_main.xml文件中添加了editText控件 <EditText        android:id="@+id/edit_text"        android:hint="@the next" <!--用the next或者@the next都报错,要使用@string/the next,用标准写法在string.xml文件中配置键值对(name:the next   vlaue:下一步),注意键值对有未使用的也会报错--&

Android Fragment 嵌套使用报错

在新的SDK每次创建activity时,会自动生成 <pre name="code" class="java">public static class PlaceholderFragment extends Fragment fragment模块,在该模块的基础上进行嵌套fragment代码如下: <pre name="code" class="java">public static class Pla

Windows下Git使用报错:warning:LF will be replaced by CRLF in &#215;&#215;&#215;&#215;.&#215;&#215;

Windows下Git使用报错: warning:LF will be replaced by CRLF in ××××.××(文件名) The file will have its original line ending in your working directory. 翻译: 在xxx.xx文件中LF将被CRLF替换. 在工作区(working directory)里,这个文件将会保持它原本的换行符.(line ending:行尾,换行) 注解:           LF:Line F

使用报错:Fatal error in launcher: Unable to create process using &#39;&quot;&#39;

在一个系统中共存Python2.python3的时候,pip.pip2.pip3使用的时候会报错: c:\Python35\Scripts>pip3Fatal error in launcher: Unable to create process using '"' 解决方法: python3: python3 -m pip install --upgrade pip python2: python2 -m pip install --upgrade pip 注意:python2, pyt

56-python pip使用报错:Fatal error in launcher: Unable to create process using &#39;&quot;&#39;

在一个系统中共存Python2.python3的时候,pip.pip2.pip3使用的时候会报错: c:\Python35\Scripts>pip3Fatal error in launcher: Unable to create process using '"' 解决方法: python3: python3 -m pip install --upgrade pip python2: python2 -m pip install --upgrade pip 注意:python2, pyt

UEditor使用报错Cannot set property &#39;innerHTML&#39; of undefined

仿用UEditor的setContent的时候报错,报错代码如下Uncaught TypeError: Cannot set property 'innerHTML' of undefined.调试ueditor.config.js,ueditor.all.js 提示me.body is undefined.(我就纳了闷儿了!同样的使用那个行这个咋就不行,那个有body,view,这个咋就这么少![我还查看了插件的内部函数,真是个good媛~])错误的原因是没有等UEditor创建完成就使用UE

Alamofire使用报错Extra argument &#39;method&#39; in call解决办法

使用Alamofire的时候,在用这句的时候报错了: Extra argument 'method' in call Alamofire.request("", method: HTTPMethod.get, parameters: [], encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in //是否请求成功 if let jsonValue = response.result.value

[Cordova+Sencha Touch] 移动开发1 sencha 2.4.0 + 在 安卓2.3.6上使用报错 - has no method &#39;bind&#39;

Sencha Touch 2.3.2和2.4.0在安卓2.3上面用会报错,具体报错信息如下: 解决办法是: 打开文件:你的file:///android_asset/www/sencha-touch-all-debug.js 找到第76728行: if (Ext.feature.has.Touch) { // bind handlers that are only invoked when the browser has touchevents me.onTargetTouchMove = me

python pip使用报错:Fatal error in launcher: Unable to create process using &#39;&quot;&#39;

系统win7 解决方法: python3: python3 -m pip install --upgrade pip python2: python2 -m pip install --upgrade pip 注意:python2, python3共存时,将python安装目录下的python.exe改成对应的python2.exe,python3.exe python pip使用报错:Fatal error in launcher: Unable to create process using