JavaScript DHTML/Style Layout/Color — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 07:28, 26 мая 2010
Содержание
Assign random color to
<html>
<head>
<title>The Node</title>
<script type="text/javascript">
function randomColor() {
r=Math.floor(Math.random() * 255).toString(16);
g=Math.floor(Math.random() * 255).toString(16);
b=Math.floor(Math.random() * 255).toString(16);
alert("#"+r+g+b);
}
randomColor();
</script>
<body onload="outputNodeProps(document)">
</body>
</html>
Body text Color
<html>
<head>
<script language="JavaScript">
function function1() {
document.all.myBody.text = "blue";
}
</script>
</head>
<body id="myBody">
Some text
<input type="button" value="Change to blue" onClick="function1();">
</body>
</html>
Change element color
<html>
<head>
<title>CSS</title>
</head>
<body>
<h1 id="h1element">The Title</h1>
<p id="firstelement">The first element.</p>
<p id="secondelement">The second element.</p>
<script type = "text/javascript" >
var element1 = document.getElementById("firstelement");
element1.style.color = "#0000FF";
</script>
</body>
</html>
Change text color
<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
function colorchange()
{
head1.style.color = "red";
}
function colorchangeback()
{
head1.style.color = "black";
}
</script>
</head>
<body>
<h1 id="head1" onMouseover="colorchange()" onMouseout="colorchangeback()">
Mouse mouse in!</h1>
</body>
</html>
"color" Example
<html>
<body>
<script language="JavaScript">
function function1() {
document.getElementById("myFont").color = "green";
}
function function2() {
document.getElementById("myFont").color = "maroon";
}
</script>
<p>
<font face="Verdana" id="myFont">
<b>Sample text.</b>
</font>
</p>
<button onClick="function1();">Make Text Green</button>
<button onClick="function2();">Make Text Maroon</button>
</body>
</html>
div.style.color="#fff";
<html>
<head>
<title>PrettyPretty</title>
<script type="text/javascript">
document.onclick=changeElement;
function changeElement() {
var div = document.getElementById("div1");
div.style.backgroundColor="#00f";
div.style.width="500px";
div.style.color="#fff";
div.style.height="200px";
div.style.paddingLeft="50px";
div.style.paddingTop="50px";
div.style.fontFamily="Verdana";
div.style.fontSize="2em";
div.style.border="3px dashed #ff0";
div.style.position="absolute";
div.style.left="200px";
div.style.top="100px";
div.style.textDecoration="underline";
}
</script>
</head>
<body>
<div id="div1">
This is a DIV element. Click me to see the change.
</div>
</body>
</html>
Foreground Color Example
<html>
<body>
Sample Text
<br>
<button onclick="document.fgColor="red";">Red</button>
<button onclick="document.fgColor="blue";">Blue</button>
</body>
</html>