HTML DOM应用案例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="tzy1.css" type="text/css">
    <script type="text/javascript" src="tzy1.js" language="JavaScript"></script>
</head>
<body>
<div id="div"><b id="b">我是一只小小鸟</b></div>
<form>
    <input type="button" value="随机改变字体颜色按钮" onclick="gbzt()">
    <input type="button" value="随机改变背景颜色按钮" onclick="gbbj()"></br>
    <input type="text" id="text">
    内容<input type="button" value="改变内容" onclick="gbtext()"></br>
    宽度<input type="text" id="gbwid">px
    <input type="button" value="改变背景宽度" onclick="gbwidth()"></br>
    高度<input type="text" id="gbhei">px
    <input type="button" value="改变背景高度" onclick="gbheight()"></br>
    <input type="reset" value="清空输入框"></br>
    <input type="button" value="字体隐藏" onclick="ycb()">
    <input type="button" value="全部隐藏" onclick="ycdiv()"></br>
    <input type="button" value="字体显示" onclick="xsb()">
    <input type="button" value="全部显示" onclick="xsdiv()"></br>
    <input type="button" value="是否重置" onclick="firm()">
</form>
</body>
</html>
div{
    color: forestgreen;
    background-color: coral;
    width: 100px;
    height: 100px;

}
var chars = [‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘,‘A‘,‘B‘,‘C‘,‘D‘,‘E‘,‘F‘];
var color;
function randomColor() {
    color="";
    for(var i=0;i<6;i++){
    var count = Math.floor(Math.random()*16);
    color += chars[count];
}
}
function gbzt() {
    randomColor();
    document.getElementById("div").style.color="#"+color;
}
function gbbj() {
    randomColor();
    document.getElementById("div").style.backgroundColor="#"+color;
}
function gbwidth() {
   var val = document.getElementById("gbwid").value;
   if(isNaN(val)||val==""){
       alert("必须输入数字,不能为空")
   }else{
    document.getElementById("div").style.width=val+‘px‘;
   }
}
function gbheight() {
    var val = document.getElementById("gbhei").value;
    if(isNaN(val)||val==""){
        alert("必须输入数字,不能为空")
    }else{
        document.getElementById("div").style.height=val+‘px‘;
    }
}
function gbtext() {
    var val = document.getElementById("text").value;
    document.getElementById("b").innerText = val;
}
function ycb() {
    document.getElementById("b").style.display = "none";
}
function ycdiv() {
    document.getElementById("div").style.display = "none";
}
function xsb() {
    document.getElementById("b").style.display = "block";
}
function xsdiv() {
    document.getElementById("div").style.display = "block";
    document.getElementById("b").style.display = "block"
}
function firm(){
    var yesorno = window.confirm("您确定取消所有设置么?")
    if(yesorno==true){
        window.location.replace("tzy1.html");
    }else{
        alert("没事瞎点什么!!!")
    }
}
时间: 2024-11-23 05:40:53

HTML DOM应用案例的相关文章

DOM综合案例、SAX解析、StAX解析、DOM4J解析

今日大纲 1.DOM技术对xml的增删操作 2.使用DOM技术完成联系人管理 3.SAX和StAX解析 4.DOM4J解析 5.XPATH介绍 1.DOM的增删操作 1.1.DOM的增加操作 /* * 演示使用dom技术给xml中添加标签 * <book> <name id="b001">SSH</name> <author>老于</author> <price>152</price> </boo

DOM操作案例之--全选与反选

全选与反选在表单类的项目中还是很常见的,电商项目中的购物车一定少不了这个功能. 下面我只就用一个简单的案例做个演示吧. <div class="wrap"> <table> <thead> <tr> <th> <input type="checkbox" id="j_cbAll"/> </th> <th>商品</th> <th>

JavaScript DOM操作案例点击按钮修改div的属性

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input type="button" value="修改属性" id="bt"/> <div id=&q

JavaScript DOM操作案例点击按钮选择菜单

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <input type="button" value="点击选择" id="bt"/&g

JavaScript DOM操作案例点击按钮通过类样式的方式显示跟隐藏div

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> div { width: 300px; height: 300px; background-color: pink; } .cls { display: none; } </style> </h

JavaScript DOM操作案例点击按钮实现网页开关灯

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> .cls { background-color: black; } </style> </head> <body> <input type="button&qu

JavaScript DOM操作案例美女相册

<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style type="text/css"> body { font-family: "Helvetica", "Arial", serif; color: #333

JavaScript DOM操作案例封装innerText跟textContent函数(浏览器兼容)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> div { width: 500px; height: 20px; border: 2px solid red; } </style> </head> <body> <i

JavaScript DOM操作案例tab切换案例

<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> * { margin: 0; padding: 0; } ul { list-style-type: none; } .box { width: 400px; height: 300px; border: 1px