Prototype - visible() 方法

此方法返回一个布尔值,指示元素是否可见,即其内联样式属性是否设置为"display: none;"。

注意 − 通过 CSS 样式表应用的样式不予考虑。请注意,这不是 Prototype 限制,而是 CSS 限制。

语法

element.visible();

返回值

HTML 元素。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            if( $('visible').visible() ) {
               alert("$('visible').visible() returns true" );
            } else {
               alert("$('visible').visible() returns false" );
            }

            if( $('hidden').visible() ) {
               alert("$('hidden').visible() returns true" );
            } else {
               alert("$('hidden').visible() returns false" );
            }
         }
      </script>
   </head>

   <body>
      <p>点击按钮查看结果</p>
      
      <div id = "visible" style = "display:block;">
         This is visible division
      </div>
      
      <div id = "hidden" style = "display: none;">
         This is hidden division
      </div>
      
      <input type = "button" value = "Click" onclick = "showResult();"/>
   </body>
</html>

输出

prototype_element_object.html