我正在尝试写一条语句,说如果#process-description内有任何东西可以显示#process-work,请隐藏它。

的HTML

 <div id="process-work">
        <h2 id="process-title">Process Work</h2>
        <p id="process-description"></p>
    </div>


JS

            'zeckoshop' : {
            'title' : 'zeckoShop',
            'description' : 'An all-in-one ecommerce platform designed to seamlessly integrate with your business operations.',
            'link' : 'http://darrenbachan.com/playground/zeckoshop/index.html',
            'images': [
                '/images/zeckoshop/zeckoshop-1.jpg'
            ],
            'tags': [
                'Web Design',
                'Web Development'
            ],
            'process-description' : 'An all-in-one ecommerce platform designed to seamlessly integrate with your business operations.',
            'process-wireframes': [
                '/images/zeckoshop/zeckoshop-1.jpg'
            ]
        }


if('#process-work') {
            $('#process-description').html(projectData['process-description']).show();
        } else {
            $('#process-work').hide();
        }

最佳答案

我认为您正在寻找代码中的此更改:

if($('#process-description').length) {
            $('#process-description').html(projectData['process-description']).show();
        } else {
            $('#process-work').hide();
        }

关于javascript - 我的if/else陈述无法执行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37222045/

10-09 09:53