Correction status:Uncorrected
Teacher's comments:
相册
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>相册</title> <style type="text/css"> .box{ width: 500px; height: 650px; background-color: #e2e2e2; border: 1px solid skyblue; margin: 20px auto; text-align: center; color: #636363; } .box ul{ margin: 0; padding: 0; overflow: hidden; } .box ul li{ border: 1px solid skyblue; list-style: none; float: left; margin-left: 20px; } .box ul li a{ display: block; width: 100px; height: 40px; line-height: 40px; color: #fff; text-decoration: none; background-color: skyblue; } .box ul li a:hover{ font-size: 1.2em; background-color: coral; } .box .pic{ width: 340px; height:350px; border: 1px solid skyblue; line-height: 1px; margin: auto; margin-top: 50px; } .box .pic img{ width: 100%; height: 100%; } #info{ margin:auto; margin-top: 50px; height: 30px; } </style> </head> <body> <div class="box"> <h2>相册</h2> <ul> <li> <a href="../img/1.png" title="《楚乔传》,《花千骨》,《陆贞传奇》..." onclick="changePic(this);return false">赵丽颖</a> </li> <li><a href="../img/1.png" title="《倚天屠龙》,《花千骨》" onclick="changePic(this);return false">高圆圆</a></li> <li><a href="../img/10.png" title="《那年花开月正圆》,《花千骨》" onclick="changePic(this);return false">孙俪</a></li> </ul> <div class="pic"> <img src="../img/2.png" alt="" id="img"> </div> <p id="info"></p> </div> <script type="text/javascript"> function changePic(pic){ // 1获取图片和标题 // 一定要加上形参pic var picimg = pic.href var picinfo = pic.title var picName = pic.innerHTML // innerHTML可以获取标签中的内容 // 2获取替换的图片和标题 var img = document.getElementById('img') var p = document.getElementById('info') // 2 = 1 img.src = picimg // 将名字和标题一起替换到P中 // js用+ 连接 p.innerHTML = picName+':'+picinfo } </script> </body> </html>
点击 "运行实例" 按钮查看在线实例
计算器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .box{ width: 400px; height: 200px; background-color: #e2e2e2; border: 1px solid skyblue; margin: 20px auto; text-align: center; color: #636363; } .box3{ margin:auto; margin-top: 20px; border: 1px solid skyblue; width: 200px; height: 35px; text-align: left; line-height: 35px; } .box3 p{ display: inline; width: 100%; height: 100%; } </style> </head> <body> <div class="box"> <h2>计算器</h2> <form class="box2"> <input type="text" name="opt1" size="10"> <select name="option"> <option value="null">請選擇</option> <option value="add">+</option> <option value="sub">-</option> <option value="mul">*</option> <option value="div">/</option> </select> <input type="text" name="opt2" size="10"> <input type="button" name="button" value="計算" id="btn"> </form> <div class="box3">結果:<p id="placeholder">1111</p></div> </div> <script type="text/javascript"> // 获取要用到的操作数 var opt1 = document.getElementsByName('opt1')[0] var opt2 = document.getElementsByName('opt2')[0] var opt = document.getElementsByName('option')[0] var btn = document.getElementsByName("button")[0] var placeholder = document.getElementById("placeholder") // 给按钮添加事件 btn.onclick = function(){ if(opt1.value.length ==0){ opt1.focus(); return false }else if(isNaN(opt1.value)){ return false }else if(opt2.value.length ==0){ opt2.focus(); return false }else if(isNaN(opt2.value)){ return false }else{ var data1 = parseFloat(opt1.value) var data2 = parseFloat(opt2.value) } // 以上是判断 // 先开始进行计算 var option = opt.value var temp = 0 var flag = '' var result = '' switch(option){ case'null': opt.focus; return false case 'add': flag = '+' temp = data1 + data2 break case 'sub': flag = '-' temp = data1 - data2 break case'mul': flag='*' temp = data1*data2 break case 'div': flag = '/' if (data2 == 0) { alert('除数不能为0,请重新输入') opt2.focus() return false } else { temp = data1 / data2 } break } // placeholder.innerHTML = data1+''+flag+''+data2+'='+temp var str ; str = data1+' '+flag+' '+data2 + ' = ' + temp placeholder.innerHTML = str } </script> </body> </html>
点击 "运行实例" 按钮查看在线实例