Jquery将动态数据传递给事件处理程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jquery将动态数据传递给事件处理程序相关的知识,希望对你有一定的参考价值。
I can see this being useful for when you want to pass a lot of associated data to an event handler from elements and their chosen trigger action.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="../assets/js/jquery.js"></script> <script type="text/javascript"> $(function () { $('#animate').bind('click', function(e){ // Do something with e.name, e.surname, etc. var newHtml = e.type || []; newHtml = e.from || $(this).attr("id"); newHtml += e.name || []; newHtml += e.surname || []; newHtml += e.age || []; newHtml += e.gender || []; $(".box").empty().append(newHtml); }); $('#animate-fake').mouseover(function() { $("#animate").trigger({ type:'click', //the bound event of the handler from:$(this).attr("id"), name:'John', surname:'Doe', age: 28, gender:'male' }); }); }); </script> </head> <body> <style type="text/css"> .box {width:100%;min-height:30px;background:#efefef;border:1px solid #ccc;} </style> <a href="#" id="animate">Show me the object</a><br /><br /> <div class="box"></div><br /><br /> <a href="#" id="animate-fake">Hover Over Me</a> </body> </html>
以上是关于Jquery将动态数据传递给事件处理程序的主要内容,如果未能解决你的问题,请参考以下文章
如何将片段中的 ListView 对象的数据传递给 Activity?
如何将变量数据传递给 createFragementContainer