【问题标题】:By selecting a class, another div display none in jquery通过选择一个类,另一个 div 在 jquery 中显示 none
【发布时间】:2015-03-26 05:41:28
【问题描述】:
    jQuery(document).ready(function() { 

         jQuery( "li.post_link_history.current" ).click(function() {
    jQuery( "div#rating-anchor" ).css( "display", "none !important" );
    }); 
});

//或

jQuery(document).ready(function() { 
       if(jQuery('li.post_link_history.current').attr('class')=='current')
        {
             jQuery('div#rating-anchor').not(jQuery(this)).css('display','none !important');
        }
    });

如何“通过选择一个类,另一个 div 在 jquery 中不显示任何内容”?

【问题讨论】:

  • .css( "display", "none !important" ) ... -> .hide()

标签: javascript jquery jquery-plugins


【解决方案1】:

您的显示样式值对内联样式无效

jQuery( "div#rating-anchor" ).css( "display", "none" );//or just call the hide() method

【讨论】:

  • 我正在为interactionlibrary.jacklynn.com/wiki/direction/?action=history 尝试此操作但不起作用? ——
【解决方案2】:
   jQuery(document).ready(function() { 

        jQuery( "li.post_link_history" ).click(function() {
              jQuery( "div#rating-anchor" ).hide();
        });
       //or 
       jQuery( "li.current" ).click(function() {
        jQuery( "div#rating-anchor" ).hide();
        }); 
       //or use an common class for "li" ex:"commonli"
 jQuery( ".commonli" ).click(function() {
         if(jQuery(this).hasClass("current")){
           jQuery( "div#rating-anchor" ).hide();
         }
        });

    });

.hide() 方法将隐藏分区。 已编辑... current 和 post_link_history 是不同的类..所以使用任何一个

【讨论】:

  • 我正在为interactionlibrary.jacklynn.com/wiki/direction/?action=history 尝试此操作但不起作用?
  • jsfiddle demo..or html
  • 检查我编辑它... current 和 post_link_history 是不同的类..所以使用任何一个..
  • 这不可能吗?
  • 对 li 使用一个通用类并将点击事件绑定到它..内部回调函数检查当前类..见我编辑它....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-28
  • 1970-01-01
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多