javascript实践-Jquery之Jquery对象与DOM对象
2014-12-16 23:23
232 查看
Window.onload=function(){
//页面加载,不能同时编写多个,最后面的会覆盖前面的
}
$(document).ready(function(){
//页面加载,能同时编写多个
});
相当于
$(function(){
//页面加载,能同时编写多个9
});
$(“#foo”).html()
相当于
Document.getElementById(“foo”).innerHTML;
Jquery对象转换成dom对象
第一种方法:
Var $cr=$(“#cr”);//jquery对象
Var cr=$cr[0];//dom对象
Alert (cr.checked);
第二种方法,通过get方法
Var $cr=$(“#cr”);//jquery对象
Var cr=$cr.get(0);//dom对象
Alert (cr.checked);
Dom对象转换成jquery对象用$(
)把对象包装起来
varcr=document.getElementById(“cr”);//获取dom对象
var $cr=$(cr); //jquery对象
jquery如果和prototype类库有冲突,jquery的$用jquery代替
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=utf-8" />
<title>冲突解决1</title>
<!--引入prototype -->
<script src="prototype-1.6.0.3.js"type="text/javascript"></script>
<!--引入jQuery -->
<script src="jquery-1.3.1.js"type="text/javascript"></script>
</head>
<body>
<p id="pp">test---prototype</p>
<p >test---jQuery</p>
<script type="text/javascript">
jQuery.noConflict(); //将变量$的控制权让渡给prototype.js
jQuery(function(){ //使用jQuery
jQuery("p").click(function(){
alert(jQuery(this).text() );});
});
$("pp").style.display ='none'; //使用prototype
</script>
</body>
</html>
第二种方法
<body>
<p id=“pp”>测试prototype</p>
<p >测试jQuery</p>
<script type="text/javascript">
var $j =jQuery.noConflict(); //自定义一个比较短快捷方式,定义$j代替$
$j(function(){ //使用jQuery
$j("p").click(function(){
alert($j(this).text() );
});
});
$("pp").style.display ='none'; //使用prototype
</script>
</body>
Window.onload=function(){
//页面加载,不能同时编写多个,最后面的会覆盖前面的
}
$(document).ready(function(){
//页面加载,能同时编写多个
});
相当于
$(function(){
//页面加载,能同时编写多个9
});
$(“#foo”).html()
相当于
Document.getElementById(“foo”).innerHTML;
Jquery对象转换成dom对象
第一种方法:
Var $cr=$(“#cr”);//jquery对象
Var cr=$cr[0];//dom对象
Alert (cr.checked);
第二种方法,通过get方法
Var $cr=$(“#cr”);//jquery对象
Var cr=$cr.get(0);//dom对象
Alert (cr.checked);
Dom对象转换成jquery对象用$(
)把对象包装起来
varcr=document.getElementById(“cr”);//获取dom对象
var $cr=$(cr); //jquery对象
jquery如果和prototype类库有冲突,jquery的$用jquery代替
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=utf-8" />
<title>冲突解决1</title>
<!--引入prototype -->
<script src="prototype-1.6.0.3.js"type="text/javascript"></script>
<!--引入jQuery -->
<script src="jquery-1.3.1.js"type="text/javascript"></script>
</head>
<body>
<p id="pp">test---prototype</p>
<p >test---jQuery</p>
<script type="text/javascript">
jQuery.noConflict(); //将变量$的控制权让渡给prototype.js
jQuery(function(){ //使用jQuery
jQuery("p").click(function(){
alert(jQuery(this).text() );});
});
$("pp").style.display ='none'; //使用prototype
</script>
</body>
</html>
第二种方法
<body>
<p id=“pp”>测试prototype</p>
<p >测试jQuery</p>
<script type="text/javascript">
var $j =jQuery.noConflict(); //自定义一个比较短快捷方式,定义$j代替$
$j(function(){ //使用jQuery
$j("p").click(function(){
alert($j(this).text() );
});
});
$("pp").style.display ='none'; //使用prototype
</script>
</body>
相关文章推荐
- javascript中jQuery对象和dom对象
- JavaScript DOM对象和JQuery对象相互转换
- JavaScript DOM对象和JQuery对象相互转换
- JavaScript学习笔记8-jQuery简介、jQuery使用详解、DOM对象与jQuery对象的转换与区别
- javascript dom对象和jQuery对象的转换
- JavaScript中将html字符串转化为Jquery对象或者Dom对象
- JavaScript 对象、DOM对象、jquery对象的区别、转换详解
- javascript对象;jquery对象;DOM对象
- JavaScript中如何将html字符串转化为Jquery对象或者Dom对象
- JavaScript中如何将html字符串转化为Jquery对象或者Dom对象
- JavaScript DOM对象和JQuery对象相互转换
- Javascript Dom对象和JQuery对象的相互转换
- JavaScript 对象、DOM对象、jquery对象的区别、转换详解
- jQuery对象和DOM对象相互转化
- jQuery-DOM对象和jQuery对象及转换
- jQuery对象与DOM对象之间的转换
- jQuery对象与DOM对象之间的转换
- [从jQuery看JavaScript]-数据类型和对象(Type and Object)(一)
- jquery对象 DOM对象 互转
- JQuery 操作Javascript对象和数组的工具函数小结