Solution for js not getting attributes to html tags

  • 2021-07-06 09:44:49
  • OfStack

javascript can't be obtained without the attribute of the tag. Remember, it can only be obtained if the attribute is written to the tag. For example, if you want to obtain id of an div, but you don't explicitly add that there is no such attribute

Before, I wondered why visibility can hide and display div while display can't. I clearly remember that it was possible before. It turned out that I wrote visibility to it in the attributes of style, but I didn't write display, but I wrote display before


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
  <head>
    <title> Basic information of vehicles </title>
    <script language="javascript" type="text/javascript"
      src="../js/autocomplete/jquery-1.7.2.min.js"></script>
    <script type="text/javascript">
     function isdisplay3(){
       var boo1 = $("#doing1").attr("style");
       var boo2 = $("#doing2").attr("style");
       if("" != boo1){
         if(document.getElementById('doing1').style.display){
           // You can't get it without writing 
           alert(" Get to doing1 Adj. display");
         }else if(document.getElementById('doing1').style.visibility){
           alert(" Get to doing1 Adj. visibility");
         }
       }

       if("" != boo2){
         if(document.getElementById('doing2').style.display){
           alert(" Get to doing2 Adj. display");
         }else if(document.getElementById('doing2').style.visibility){
          // You can't get it without writing 
           alert(" Get to doing2 Adj. visibility");
         }
       }

       
     }
    </script>
  </head>
  <body>
    <input type="button" value=" Layer " onclick="isdisplay3()" />
    <div id="doing1" style="visibility: hidden">
    </div>

    <div id="doing2" style="display: none">
    </div>
  </body>
</html>

Related articles: