<!DOCTYPE html>
<html>
<head>
<title>使用$.extend()扩展工具函数</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="http://www.imooc.com/data/jquery-1.8.2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="divtest">
<div class="title">
<span class="fl">自定义工具函数求两值中最小值</span>
<span class="fr">
<input id="btnShow" name="btnShow" type="button" value="计算" />
</span>
</div>
<div class="content">
<div class="tip"></div>
</div>
</div>
<script type="text/javascript">
/*------------------------------------------------------------/
功能:返回两个数中最小值
参数:数字p1,p2
返回:最小值的一个数
示例:$.MinNum(1,2);
/------------------------------------------------------------*/
(function ($) {
?({
"MinNum": function (p1, p2) {
return (p1 > p2) ? p2 : p1;
}
});
})(jQuery);
$(function () {
$("#btnShow").bind("click", function () {
$(".tip").html("");
var strTmp = "17与18中最小的数是:";
strTmp +=? (17, 18);
//显示在页面中
$(".tip").show().append(strTmp);
});
});
</script>
</body>
</html>
#divtest
{
width: 302px;
}
#divtest .title
{
padding: 8px;
background-color: Red;
color: #fff;
height: 23px;
line-height: 23px;
font-size: 15px;
font-weight: bold;
}
#divtest .content
{
padding: 8px;
background-color: #fff;
font-size: 13px;
}
#divtest .content .tip
{
border: solid 1px #ccc;
background-color: #eee;
margin: 10px 0px;
padding: 8px;
display: none;
}
.fl
{
float: left;
}
.fr
{
float: right;
}