jQuery的 - 如何设置父属性? [英] jquery - how to set parent attribute?

查看:119
本文介绍了jQuery的 - 如何设置父属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个if语句,如果在那里的要素之一有它的显示设置为无,我想父元素也显示无...

这是code我想,这是不行的......

  / *尝试这第一个* /
如果($('#preVX A')。ATTR('显示器')=='无'){
    $(本).parent()ATTR('显示器','无')。
}/ *然后将此* /
如果($('#prevxa>将')ATTR('显示器')=='无'){
    $('#prevxa')ATTR('显示器','无')。
}

的标记看起来是这样的:

 < UL>
   <李班=navnextID =nextxa>
      &下;一个ID =nextx的href =#>&下; IMG SRC =/图片/ next.png/>&下; / A>
   < /李>   <李班=资产净值preVID =prevxa>
      <一个ID =preVX的href =#的风格=显示:无;>< IMG SRC =/图像/ previous.png/>< / A>
   < /李>
< / UL>


解决方案

试试这个:

 如果($('#preVX')。CSS('显示器')=='无'){
    。$('#preVX')父()的CSS('显示器','无');
}

更重要的是:

  $('#preVX')。父()。CSS('显示器',$('#preVX')。CSS('显示器') );

这个例子对我的作品。要隐藏/显示父,没有切换和内联之间的孩子的显示:

 < UL>
   <李班=navnextID =nextxa>
      &下;一个ID =nextx的href =#>&下; IMG SRC =/图片/ next.png/>&下; / A>
   < /李>   <李班=资产净值preVID =prevxa>
      <一个ID =preVX的href =#的风格=显示:内联;>< IMG SRC =/图像/ previous.png/>< / A>
   < /李>
< / UL><脚本>
如果($('#preVX')。CSS('显示器')=='无')
    。$('#preVX')父()的CSS('显示器','无');
其他
    。$('#preVX')父()的CSS('显示器','列表项');
< / SCRIPT>

I'm trying to write an if statement where if one of the elements has it's display set to "none", I want the parent element to also display "none"...

This is the code I'm trying, which doesn't work...

/* tried this first */
if($('#prevx a').attr('display') == 'none') {
    $(this).parent().attr('display','none');
}

/* and then this */
if($('#prevxa > a').attr('display') == 'none') {
    $('#prevxa').attr('display','none');
}

The markup looks like this:

<ul>
   <li class="navnext" id="nextxa">
      <a id="nextx" href="#"><img src="/images/next.png"/></a>
   </li>

   <li class="navprev" id="prevxa">
      <a id="prevx" href="#" style="display: none;"><img src="/images/previous.png"/></a>
   </li>
</ul>

解决方案

Try this:

if($('#prevx').css('display') == 'none') {
    $('#prevx').parent().css('display','none');
}

Better yet:

$('#prevx').parent().css('display',$('#prevx').css('display'));

This example works for me. To hide/display the parent, toggle the child's display between none and inline:

<ul>
   <li class="navnext" id="nextxa">
      <a id="nextx" href="#"><img src="/images/next.png"/></a>
   </li>

   <li class="navprev" id="prevxa">
      <a id="prevx" href="#" style="display: inline;"><img src="/images/previous.png"/></a>
   </li>
</ul>

<script>
if ($('#prevx').css('display') == 'none') 
    $('#prevx').parent().css('display', 'none');
else
    $('#prevx').parent().css('display', 'list-item');
</script>

这篇关于jQuery的 - 如何设置父属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆