Javascript变量 - 设置为百分比

时间:2011-10-04 14:46:03

标签: javascript jquery html

<div class="contentBlockOne">
        <span class="moreButton">More</span>
        <br />Each block will have an article summary in it.</div>

我希望使用以下jQuery增加“跨度”点击的“Div”的宽度(我没有打扰包括其他部分):

            var currentWidth = $('.moreButton').parent().width();               
            $('.moreButton').click(function () {
                if ($(this).parent().width == currentWidth) {
                    $(this).parent().animate({ width: '98%' }, 800);                        
                    $(this).text('Less');
                }

在我的脑海中,“currentWidth”变量应与父母宽度相同。但是在调试时,代码没有做任何事情。我认为这是因为,无论如何,两个宽度值不一样。

1 个答案:

答案 0 :(得分:4)

您在.width()来电时缺少括号。变化:

if ($(this).parent().width == currentWidth) {
// to
if ($(this).parent().width() == currentWidth) {
相关问题