基本上我正在做的是制作“查看更多”类型的东西。我有一小段文字描述了我从事的工作,并在段落末尾有一个按钮。我(它真的是一个链接,带有按钮样式)。当按下按钮时,div 扩展为 400px,并使用 .html() 添加额外的文本;但是当我点击“少看”按钮折叠回较小的段落和 200px div 时,什么也没有发生。
jQuery
$(document).ready(function(){
var $mottheight = $('#row-mott').height();
if ( $mottheight == 300 ) {
$('#mott-btn-collapse').click(function(){
$('#row-mott').animate({
height:200
}, 300);
$('#mott').html('I\'ve worked on the Warren Mott High School website since September of 2011. I am one of four student webmasters that keep the website in the best condition possible. We cannot take credit for all the coding, though. This website is run by around 40 Web Design students. As Webmaster, my job is to fix, improve, and help those students learn as they go. <a href="#" id="mott-btn" class="btn btn-mini">Less info »</a>');
});
}
else if ( $mottheight < 300 ){
$('#mott-btn').click(function(){
$('#row-mott').animate({
height:300
}, 400);
$('#mott').html('I\'ve worked on the Warren Mott High School website since September of 2011. I am one of four student webmasters that keep the website in the best condition possible. We cannot take credit for all the coding, though. This website is run by around 40 Web Design students. As Webmaster, my job is to fix, improve, and help those students learn as they go. I\'ve worked on the Warren Mott High School website since September of 2011. I am one of four student webmasters that keep the website in the best condition possible. We cannot take credit for all the coding, though. This website is run by around 40 Web Design students. As Webmaster, my job is to fix, improve, and help those students learn as they go. I\'ve worked on the Warren Mott High School website since September of 2011. I am one of four student webmasters that keep the website in the best condition possible. We cannot take credit for all the coding, though. This website is run by around 40 Web Design students. As Webmaster, my job is to fix, improve, and help those students learn as they go. <a href="#" id="mott-btn-collapse" class="btn btn-mini">Less info »</a>');
});
}
else {
return 0;
}
});