JavaScript DHTML/Ext JS/HTML

Материал из Web эксперт
Перейти к: навигация, поиск

Add child tag to div tag

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> <style type="text/css"> div {

 border  : 1px solid #AAAAAA; 
 width   : 200; 
 cursor  : pointer;
 padding : 2px 2px 2px 2px;
 margin  : 2px 2px 2px 2px;  

} </style> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 
 myDiv1.createChild({
     tag  : "div",
     html : "Child " + 1 
 });

}); </script>

asdf
asdf2

</body> </html>

 </source>
   
  


Add click event handler to div tag

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> </head> <body> <script type="text/javascript"> Ext.onReady(function() {


   Ext.get("div1").on("click", function(eventObj, elRef) {
        alert("myDiv click Handler, source elment ID: " +  elRef.id);
   });


}); </script>

asdf

</body> </html>

 </source>
   
  


Align div tag to another tag

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> <style type="text/css"> div {

 border  : 1px solid #AAAAAA; 
 width   : 200; 
 cursor  : pointer;
 padding : 2px 2px 2px 2px;
 margin  : 2px 2px 2px 2px;  

} </style> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 
 myDiv1.alignTo("div1", "div2");

}); </script>

asdf
asdf2

</body> </html>

 </source>
   
  


Child from a config object

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 myDiv1.createChild({
   tag  : "div",
   html : "Child from a config object"
 });


}); </script>

</body> </html>

 </source>
   
  


Create Child for Div tag

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 myDiv1.createChild("Child from a string");

}); </script>

</body> </html>

 </source>
   
  


Create child for div tag with html tags

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
myDiv1.createChild("
Element from a string
");

}); </script>

</body> </html>

 </source>
   
  


Get last children

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> <style type="text/css"> div {

 border  : 1px solid #AAAAAA; 
 width   : 200; 
 cursor  : pointer;
 padding : 2px 2px 2px 2px;
 margin  : 2px 2px 2px 2px;  

} </style> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 
   var lastChild   = Ext.get("div1").child("div:last-child");

}); </script>

asdf
asdf2

</body> </html>

 </source>
   
  


Get width and height of a Div tag

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> <style type="text/css"> div {

 border  : 1px solid #AAAAAA; 
 width   : 200; 
 cursor  : pointer;
 padding : 2px 2px 2px 2px;
 margin  : 2px 2px 2px 2px;  

} </style> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
   myDiv1.setSize(200, 300, true);
 alert(myDiv1.getWidth());
 alert(myDiv1.getHeight()); 

}); </script>

asdf

</body> </html>

 </source>
   
  


Insert child as node to a div tag

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 myDiv1.insertFirst({
   tag  : "div",
   html : "Child inserted"
 });


}); </script>

</body> </html>

 </source>
   
  


Insert node to an indexed position

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 myDiv1.insertFirst({
   tag  : "div",
   html : "Child inserted"
 });
 myDiv1.insertFirst({
   tag  : "div",
   html : "Child inserted"
 });
 myDiv1.insertFirst({
   tag  : "div",
   html : "Child inserted"
 });
 myDiv1.createChild({
   tag  : "div",
   id   : "id",
   html : "Child inserted"
 }, myDiv1.dom.childNodes[3]);

}); </script>

</body> </html>

 </source>
   
  


Nested div tag with border

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 myDiv1.createChild({
   tag      : "div",
   id       : "nestedDiv",
   style    : "border: 1px dashed; padding: 5px;",
   children : {
      tag  : "div",
      html : "A nested div",
      style : "color: red; border: 1px solid"
   }
 });


}); </script>

</body> </html>

 </source>
   
  


Put mask to a div tag

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> <style type="text/css"> div {

 border  : 1px solid #AAAAAA; 
 width   : 200; 
 cursor  : pointer;
 padding : 2px 2px 2px 2px;
 margin  : 2px 2px 2px 2px;  

} </style> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 
 myDiv1.mask("No more action!");

}); </script>

asdf
asdf2

</body> </html>

 </source>
   
  


Remove a tag from html body

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> <style type="text/css"> div {

 border  : 1px solid #AAAAAA; 
 width   : 200; 
 cursor  : pointer;
 padding : 2px 2px 2px 2px;
 margin  : 2px 2px 2px 2px;  

} </style> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 
   myDiv1.remove();

}); </script>

asdf
asdf2

</body> </html>

 </source>
   
  


Set Div tag size

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> <style type="text/css"> div {

 border  : 1px solid #AAAAAA; 
 width   : 200; 
 cursor  : pointer;
 padding : 2px 2px 2px 2px;
 margin  : 2px 2px 2px 2px;  

} </style> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
   myDiv1.setSize(200, 300, true);

}); </script>

asdf

</body> </html>

 </source>
   
  


Set style for created children

   <source lang="html4strict">

<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 myDiv1.createChild({
   tag      : "div",
   id       : "nestedDiv",
   style    : "border: 1px dashed; padding: 5px;",
 });


}); </script>

</body> </html>

 </source>
   
  


Use update method to set new text for div tag

   <source lang="html4strict">


<html> <head> <title>Hello World Window</title> <link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" /> <script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-3.0.0/ext-all.js"></script> <style type="text/css"> div {

 border  : 1px solid #AAAAAA; 
 width   : 200; 
 cursor  : pointer;
 padding : 2px 2px 2px 2px;
 margin  : 2px 2px 2px 2px;  

} </style> </head> <body> <script type="text/javascript"> Ext.onReady(function() {

 var myDiv1 = Ext.get("div1");
 var newX = 50;
 var newY = 10;
 
 myDiv1.moveTo(newX, newY, {
   callback : function() {
     var msgX = Math.ceil(this.getX());
     var msgY= Math.ceil(this.getY());        
     var msg = "X = " + msgX + " Y = " + msgY;
     this.update(msg);
   }
 });

}); </script>

asdf

</body> </html>

 </source>