首页 > 代码库 > jQuery 对象转成 DOM 对象
jQuery 对象转成 DOM 对象
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> <script type="text/javascript" src="http://www.mamicode.com/js/jquery-1.8.0.js"></script> </head> <body> <h1>DOM 对象转成 jQuery 对象 示例</h1> <script type="text/javascript"> $(document).ready(function() { //1、jQuery 对象是一个数组对象, 可以通过 [index] 的方法得到对应的 DOM对象. var $div2=$("#myid"); $div2.click(function(){ alert($div2); var dom=$div2[0]; alert(dom.title); }); //2、使用 jQuery 中的 get(index) 方法得到相应的 DOM 对象 var $div3=$(".myclass"); $div3.click(function(){ alert($div3); var dom2=$div3.get(0); alert(dom2.title); }); }); </script> <div id="myid" title="myid"> <p>hello jquery myid</p> </div> <div class="myclass" title="myclass"> <p>hello jquery myclass</p> </div> </body> </html>
jQuery 对象转成 DOM 对象
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。