脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-jquery第三期:js与jquery对象转换,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。 我们开始进入jquery的学习了,jquery的学习就不那么中规中矩了,我们来看一个和javascript有所区别的地方。
<!DOCTYPE html PubLIC "-//W3C//DTD HTML 4.01 TransITional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.10.1.js"></script>
<script type="text/javascript">
window.onload = function()
{
alert("niujiabin");
}
window.onload = function()
{
alert("bcd");
}
</script>
</head>
<body>
</body>
</html>
结果是:
弹出niujiabinbin的提示框,但是我们改写成jquery:
[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.10.1.js"></script>
<script type="text/javascript">
$(function()
{
alert("abc");
});
$(function(){
alert("bcd");
});
</script>
</head>
<body>
</body>
</html>
结果却是两个都输出了,我们可以看出,jquery的加载方式进行了变化,那么这样的好处是什么呢?
如果引用两个js文件的function,那么会产生覆盖问题,jquery使用闭包解决了此问题。
下面我们看一看js对象和jquery对象:
下面的代码能找出错误么?
[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.10.1.js"></script>
<script type="text/javascript">
$(function()
{
VAR hello = document.getElementById("hello");
hello.css("color","red");
});
</script>
</head>
<body>
<p id="hello">
<ul>
<li>niujiabin</li>
<li class="abc">maybe</li>
<li>gossipgo</li>
</ul>
</p>
</body>
</html>
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-jquery第三期:js与jquery对象转换全部内容,希望文章能够帮你解决javascript代码实例教程-jquery第三期:js与jquery对象转换所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。