1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Insert title here</title> 6 <script type="text/javascript" src="js/jquery-1.8.3.js"></script> 7 </head> 8 <body> 9 <input type="text" id="text1" value="text" /> 10 <script type="text/javascript"> 11 //dom对象获取 12 var text = document.getElementById("text1"); 13 //alert(text1.value); 14 15 //jQuery获取 16 var $text1 = $(text1); 17 //alert($text1.val()); 18 var $text2 = jQuery(text1); 19 //alert($text2.val()); 20 var $text3 = $("#text1"); 21 //alert($text3.val()); 22 23 //jQuery转dom对象的两种方法 24 var text2 = $text1[0]; 25 //alert(text2.value); 26 var text3 = $text1.get(0); 27 //alert(text3.value); 28 29 //dom对象转jQuery 30 var $text4 = $(text); 31 //alert($text4.val()); 32 </script> 33 </body> 34 </html>
源码链接http://code.jquery.com/jquery-1.8.3.min.js
jQuery对象和dom对象的转换
原文地址:https://www.cnblogs.com/xiaostudy/p/9557442.html
时间: 2024-10-31 07:06:30