本文实例讲述了jQuery基于闭包实现的显示与隐藏div功能。分享给大家供大家参考,具体如下
本文实例讲述了jQuery基于闭包实现的显示与隐藏div功能。分享给大家供大家参考,具体如下:
<div class="binds">
<div class="phonebind">
<h3>手机绑定</h3>
<p>当前手机号码:<span id="oldPhone">$!{user.phone}</span><input type="button" class="btnInput" id="rebindPhone" value="重新绑定"></p>
<div class="updatetelwrap hidden">
<div class="newphonewrap">
<label>新手机号码<em>*</em></label>
<input type="text" class="formatText" id="newPhone" />
</div>
<div class="identifywrap">
<label>短信验证码<em>*</em></label>
<input type="text" class="inputcode" />
<input type="button" value="获取短信验证码" class="identifycode"/>
<p><input type="button" value="绑定" class="bindbtn" id="newphonebind" style="float: left;" onclick="javascript:bindPhone();" /></p>
</div>
</div>
</div>
<div class="emailbind">
<h3>邮箱绑定</h3>
<p>当前电子邮箱:<span id="oldEmail">$!{user.email}</span><input type="button" class="btnInput" value="重新绑定" id="rebindEmail"></p>
<div class="update-email-wrap hidden">
<div class="emailwrap">
<label>新电子邮箱<em>*</em></label>
<input type="text" class="formatText" id="newEmail" />
<p><input type="button" value="发送验证邮件" id="sendEmail" style="float: left;" class="btnInput" onclick="javascript:bindEmail();" /></p>
</div>
</div>
</div>
</div>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(function(){
$(document).on("click","#rebindPhone",bindInputclick());
$(document).on("click","#rebindEmail",bindInputclick());
})
function bindInputclick(){
var i=2;
return function(){
if(i%2==0){
$(this).parent().next().slideDown();
}
else {
$(this).parent().next().slideUp();
}
i++;
}
}
</script>
感兴趣的朋友还可以使用在线HTML/CSS/JavaScript代码运行工具 http://tools.jb51.net/code/HtmlJsRun测试一下运行效果。
jQuery 闭包 显示 隐藏 div