JavaScript DHTML/Ext JS/HTML
Содержание
- 1 Add child tag to div tag
- 2 Add click event handler to div tag
- 3 Align div tag to another tag
- 4 Child from a config object
- 5 Create Child for Div tag
- 6 Create child for div tag with html tags
- 7 Get last children
- 8 Get width and height of a Div tag
- 9 Insert child as node to a div tag
- 10 Insert node to an indexed position
- 11 Nested div tag with border
- 12 Put mask to a div tag
- 13 Remove a tag from html body
- 14 Set Div tag size
- 15 Set style for created children
- 16 Use update method to set new text for div tag
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>
</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>
</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>
</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("
}); </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>
</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>
</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>
</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>
</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>
</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>
</body> </html>
</source>