您的位置:首页 > Web前端 > JQuery

jQuery之插件开发--jQuery.fn.extend()

2017-07-04 20:19 375 查看
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<script src="jquery.js"></script>
<script src="jqui/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="jqui/jquery-ui.css">
<style type="text/css">
.dialog{
display: none;
}
</style>

<script type="text/javascript">
(function($){
$.fn.extend({
test:function(){
this.click(function(){
alert($(this).val())
});
},
dialogTest:function(){
var _this = this;
$('.dialog').dialog({
modal:true,
buttons:{
确定:function(){
rs = $('input[name=id]').val();
_this.html(rs);
$(this).dialog('close');
}
}
});
return this;
}
});
})(jQuery);
</script>
</head>
<body>
<div class="show"></div>
<button id="me">Click Me</button>
<div class="dialog">
<input type="text" name="id" placeholder="请输入ID">
</div>

<script type="text/javascript">
$('body').on('click', '#me', function(){
$('.show').dialogTest();
});
</script>
</body>
</html>


jQuery.f
835f
n.extend 可以写扩展插件

以上为Demo
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: