jQuery中live()使用报错,TypeError: $(...).live is not a function(转)
2017-09-29 11:55
561 查看
jQuery中live()使用报错,TypeError: $(…).live is not a function
<div class="article_manage clearfix"> <div class="article_r"> <span class="link_postdate">2017-03-02 16:01</span> <span class="link_view" title="阅读次数">761人阅读</span> <span class="link_comments" title="评论次数"> <a href="#comments" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_pinglun'])">评论</a>(0)</span> <span class="link_collect tracking-ad" data-mod="popu_171"> <a href="javascript:void(0);" onclick="javascript:collectArticle('jQuery%e4%b8%adlive()%e4%bd%bf%e7%94%a8%e6%8a%a5%e9%94%99%ef%bc%8cTypeError%3a+%24(...).live+is+not+a+function','59536781');return false;" title="收藏" target="_blank">收藏</a></span> <span class="link_report"> <a href="#report" onclick="javascript:report(59536781,2);return false;" title="举报">举报</a></span> </div> </div> <style type="text/css"> .embody{ padding:10px 10px 10px; margin:0 -20px; border-bottom:solid 1px #ededed; } .embody_b{ margin:0 ; padding:10px 0; } .embody .embody_t,.embody .embody_c{ display: inline-block; margin-right:10px; } .embody_t{ font-size: 12px; color:#999; } .embody_c{ font-size: 12px; } .embody_c img,.embody_c em{ display: inline-block; vertical-align: middle; } .embody_c img{ width:30px; height:30px; } .embody_c em{ margin: 0 20px 0 10px; color:#333; font-style: normal; } </style> <script type="text/javascript"> $(function () { try { var lib = eval("("+$("#lib").attr("value")+")"); var html = ""; if (lib.err == 0) { $.each(lib.data, function (i) { var obj = lib.data[i]; //html += '<img src="' + obj.logo + '"/>' + obj.name + " "; html += ' <a href="' + obj.url + '" target="_blank">'; html += ' <img src="' + obj.logo + '">'; html += ' <em><b>' + obj.name + '</b></em>'; html += ' </a>'; }); if (html != "") { setTimeout(function () { $("#lib").html(html); 4000 $("#embody").show(); }, 100); } } } catch (err) { } }); </script> <div class="category clearfix"> <div class="category_l"> <img src="http://static.blog.csdn.net/images/category_icon.jpg"> <span>分类:</span> </div> <div class="category_r"> <label onclick="GetCategoryArticles('6759992','sdfdyubo','top','59536781');"> <span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">jQuery<em>(1)</em></span> <img class="arrow-down" src="http://static.blog.csdn.net/images/arrow_triangle _down.jpg" style="display:inline;"> <img class="arrow-up" src="http://static.blog.csdn.net/images/arrow_triangle_up.jpg" style="display:none;"> <div class="subItem"> <div class="subItem_t"><a href="http://blog.csdn.net/sdfdyubo/article/category/6759992" target="_blank">作者同类文章</a><i class="J_close">X</i></div> <ul class="subItem_l" id="top_6759992"> </ul> </div> </label> <label onclick="GetCategoryArticles('6759993','sdfdyubo','top','59536781');"> <span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">Html<em>(1)</em></span> <img class="arrow-down" src="http://static.blog.csdn.net/images/arrow_triangle _down.jpg" style="display:inline;"> <img class="arrow-up" src="http://static.blog.csdn.net/images/arrow_triangle_up.jpg" style="display:none;"> <div class="subItem"> <div class="subItem_t"><a href="http://blog.csdn.net/sdfdyubo/article/category/6759993" target="_blank">作者同类文章</a><i class="J_close">X</i></div> <ul class="subItem_l" id="top_6759993"> </ul> </div> </label> <label onclick="GetCategoryArticles('6758438','sdfdyubo','top','59536781');"> <span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">javascript学习笔记<em>(1)</em></span> <img class="arrow-down" src="http://static.blog.csdn.net/images/arrow_triangle _down.jpg" style="display:inline;"> <img class="arrow-up" src="http://static.blog.csdn.net/images/arrow_triangle_up.jpg" style="display:none;"> <div class="subItem"> <div class="subItem_t"><a href="http://blog.csdn.net/sdfdyubo/article/category/6758438" target="_blank">作者同类文章</a><i class="J_close">X</i></div> <ul class="subItem_l" id="top_6758438"> </ul> </div> </label> </div> </div>
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)
document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000)
<div id="digg" articleid="59536781"> <dl id="btnDigg" class="digg digg_enable" onclick="btndigga();"> <dt>顶</dt> <dd>0</dd> </dl> <dl id="btnBury" class="digg digg_enable" onclick="btnburya();"> <dt>踩</dt> <dd>0</dd> </dl> </div> <div class="tracking-ad" data-mod="popu_222"><a href="javascript:void(0);" target="_blank"> </a> </div> <div class="tracking-ad" data-mod="popu_223"> <a href="javascript:void(0);" target="_blank"> </a></div> <script type="text/javascript"> function btndigga() { $(".tracking-ad[data-mod='popu_222'] a").click(); } function btnburya() { $(".tracking-ad[data-mod='popu_223'] a").click(); } </script>
相关文章推荐
- 关于jquery使用live()方法的问题Uncaught TypeError: $(...).live is not a function
- jQuery中live()使用报错,TypeError: $(...).live is not a function
- 使用jquery插件autocomplete时候出现typeerror:this.source is not a function即与jquery的autocomplete冲突
- jquery版本更新后无live函数的处理.TypeError: $(...).live is not a function
- TypeError: a(...).live is not a function(jquery.unobtrusive-ajax.min.js 引入报错)
- jquery-ui.min.js:5 Uncaught TypeError: b.nodeName.toLowerCase is not a function
- jquery中Uncaught TypeError: $(...).ajaxUpload is not a function(…)错误解决方法
- TypeError: $ is not a function when calling jQuery function
- jquery TypeError: U[a].exec is not a function 是咋个回事
- 【JQuery】sortable.js Uncaught TypeError $(...).sortable is not a function
- TypeError: url.indexOf is not a function ,使用jquery load()出现错误
- vue项目使用手机浏览器访问时报错:Uncaught TypeError: Object.assign is not a function
- Uncaught TypeError: $(...).Validform is not a function 如何解决,以及其他方式替换jquery功能
- TypeError: jQuery(...).validationEngine is not a function
- Jquery报错:Uncaught TypeError: ((m.event.special[e.origType] || (intermediate value)).handle || e.handler).apply is not a function
- jquery.js里面报错Uncaught TypeError: a.indexOf is not a function
- 关于Jquery错误的解决:Uncaught TypeError: $.post is not a function
- jquery.min.js:2 Uncaught TypeError: $(...).DataTable is not a function
- jquery TypeError: 'undefined' is not a function (evaluating 'elem.nodeName.toLowerCase()') [jquery.js:1904]错误原因
- TypeError: jQuery.easing[this.easing] is not a function