发布于 2017-04-19 01:46:27 | 115 次阅读 | 评论: 0 | 来源: 网友投递
jQuery javascript框架
jQuery是一个兼容多浏览器的javascript框架,核心理念是write less,do more(写得更少,做得更多)。jQuery在2006年1月由美国人John Resig在纽约的barcamp发布,吸引了来自世界各地的众多JavaScript高手加入,由Dave Methvin率领团队进行开发。
(function ($) {
/* 这里放置代码 */
})(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><title></title>
<style type="text/css">
li { border: 1px solid #000; cursor: pointer; width: 200px; display: block; }
</style>
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function ($) {
$.fn.extend({
"chgSC": function (options) {
options = $.extend({ FontSize: "100px", Color: "red" }, options); //这里用了$.extend方法,扩展一个对象
return this.hover(function () { //return为了保持jQuery的链式操作
$(this).css({ "fontSize": options.FontSize, "color": options.Color });
}, function () {
$(this).css({ "fontSize": "", "color": "" });
});
}
});
$.extend({
"urlParam": function () {
var pageUrl = location.search;
if (pageUrl != "")
return pageUrl.slice(1);
else
return "没有参数";
}
});
})(jQuery);
$(function () {
$("li").chgSC({ FontSize: "130px" });
alert($.urlParam());
});
</script>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</body>
</html>