简单普通DOM对象与jquery之间的转换

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>普通dom对象与jquery对象之间的转换</title>
</head>
<script language="javascript" type="text/javascript" src="../../include/jquery.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function (){
  //1、普通DOM对象转换jquery对象
  var dname=document.getElementById("username");
  //alert(dname);
  var jname=$(dname);
  alert(jname.val());
  
  //2、jquery对象转换普通dom对象(有两种方法)
   1)var domname=$("#username").get(0);
   2)var domname=$("#username")[0];
   alert(domname.value);
  
 
});

</script>
<body>
<input type="text" value="张三" id="username">
</body>
</html>

你可能感兴趣的:(JavaScript,html,jquery,XHTML,function)