简体   繁体   English

如果使用ul标签,为什么不能向上滑动?

[英]Why slide up doesn't work if I use ul tag?

I want to pull up/slide up my Html "p" tag when my page has been loaded. 当页面加载后,我想拉/滑我的Html“ p”标签。

This jQuery code works fine and does that: 此jQuery代码可以正常运行,并且可以做到这一点:

$(function () {
    $('.graybgc').slideUp(0);
});

HTML: HTML:

<p class="graybgc">
    <span>A: </span>abcd.....
</p>

But when I put some tags like ul, it doesn't works and doesn't pull up HTML p tag. 但是,当我放置ul之类的标签时,它不起作用,也不会拉起HTML p标签。

 <p class="graybgc">
       <span>A: </span>
          <ul >
            <li>123</li>
             <li>123</li>
          </ul>
</p>

You cannot put a ul tag inside of a p tag. 您不能将ul标记放在p标记内。 Please check HTML specification . 请检查HTML规范

Here is a working example using div tag (JSFiddle: https://jsfiddle.net/Hulothe/sa09gu46/ ) : 这是一个使用div标签的工作示例(JSFiddle: https ://jsfiddle.net/Hulothe/sa09gu46/):

 $('.graybgc').on('click', function() { $(this).slideUp(0); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="graybgc" > <span>A: </span> <ul> <li>123</li> <li>123</li> </ul> </div> 

Use <DIV> instead of <p> 使用<DIV>代替<p>

<div class="graybgc">
       <span>A: </span>
          <ul >
            <li>123</li>
             <li>123</li>
          </ul>
</div>

 $('.graybgc').on('click', function() { $(this).slideUp("slow"); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="graybgc" style="background:red" > <span>A: </span> <ul> <li>123</li> <li>123</li> </ul> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM