http://www.fgm.cc/learn/

First class ,6 examples anlaysisi

 <!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Change Attribute?</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
* {
padding:0;
margin:0;
}
#changeAttr{
width:370px;
/*width:auto or 100%, not center*/
margin:100px auto;
border:1px solid #000000;
padding:50px; }
#obj{
width:150px;
margin:20px auto;
height:150px;
background-color:black;
}
</style>
</head>
<body>
<div id='changeAttr'>
<h1>Change Attribute</h1>
<div id='content'>
<input id='chWidth' type='button' value='CH WIDTH'/>
<input id='chHeight' type='button' value='CH HIGHT'/>
<input id='chColor' type='button' value='CH COLOR'/>
<input id='chHide' type='button' value='CH HIDE'/>
<input id='chReset' type='button' value='CH RESET'/>
<div id='obj'></div>
</div>
</div>
<script>
// window.onload = function(){
// var chWidth = document.getElementById("chWidth");
// var chHeight = document.getElementById("chHeight");
// var chColor = document.getElementById("chColor");
// var chHide = document.getElementById("chHide");
// var chReset = document.getElementById("chReset");
// var obj = document.getElementById("obj");
//
// chWidth.onclick = function(){
// obj.style.width = '300px';
// }
// chHeight.onclick = function(){
// obj.style.height = '300px';
// }
// chColor.onclick = function(){
// obj.style.backgroundColor = '#ff0000';
// }
// chHide.onclick = function(){
// obj.style.display = 'none';
// }
// chReset.onclick = function(){
// obj.style.width = '150px';
// obj.style.height = '150px';
// obj.style.backgroundColor = '#000000';
// obj.style.display = 'block';
// }
// } // var changeStyle = function (elem, attr, value)
// {
// elem.style[attr] = value
// };
// window.onload = function ()
// {
// var oBtn = document.getElementsByTagName("input");
// var oDiv = document.getElementById("obj");
// var oAtt = ["width","height","background","display","display"];
// var oVal = ["200px","200px","red","none","block"];
//
// for (var i = 0; i < oBtn.length; i++)
// {
// oBtn[i].index = i;
// oBtn[i].onclick = function ()
// {
// this.index == oBtn.length - 1 && (oDiv.style.cssText = "");
// console.log(this.index);
// changeStyle(oDiv, oAtt[this.index], oVal[this.index])
// }
// }
// }; var changeStyle = function(ele,attr,val){
ele.style[attr] = val;
};
window.onload = function(){
var oBtn = document.getElementsByTagName("input");
var oDiv = document.getElementById("obj");
var oAttr = ["width","height","backgroundColor","display","display"];
var oVal = ["200px","200px","red","none","block"]; for(var i=0;i<oBtn.length;i++){
oBtn[i].index = i;
oBtn[i].onclick = function(){ this.index == oBtn.length - 1 && (oDiv.style.cssText = "");
//console.log(this.index);
changeStyle(oDiv,oAttr[this.index],oVal[this.index]);
};
}
} </script>
</body>
</html>

1.width auto or 100%, not center;

2.good at using for ,like getElementsByTagName('input');

3.this.index == oBtn.length - 1 && (oDiv.style.cssText = ""); like

  if(a >=5){
  alert("你好");
  }
  可以写成:
  a >= 5 && alert("你好");

4. look at 3,oDiv.style.cssText = "",all recover,it means add style through js,then the style go to html lines, when you clean style,you just clean style inline,not the style in<style> or stylesheet.

1.首次打开页面时候便已有默认风格
  不好:在全局里面设置一次风格,然后在onclick里面在写一遍同样的代码
  改进:在<style>先给风格,只是以后点击会更换风格,减少代码量

2.border:横排 有重复边
  不好:给每个子元素每边都加,然后统一去掉右边框,最好给父元素或最后一个子加一个右边框
  改进:父每边都有,子统一有右边框,最后去掉最后子的右边框;来回折腾的减少
3.<li>red</li> 加text-indent:-9999px;方便理解

4.去掉外层div ,当里面li:float:left时,ul仍然可以包住li
5.<a href="javascript:;"></a>

1. input 前必须加#content,否则margin-bottom会被#content中的margin覆盖,(优先级不够),by the way,有padding好看多了

#################################################################################

1.text-align:center,对div:block不管用,对inline-block管用
2.子元素float之后,父{width:xxxpx;margin:0 auto;},此时虽然没有包住子,但子依然居中;父加上height,就包住子

#########################################################################

First class ,6 examples anlaysisi的更多相关文章

  1. Js: Extensible Calendar Examples

    http://ext.ensible.comhttps://github.com/bmoeskau/Extensiblehttps://github.com/TeamupCom/extensibleh ...

  2. Selenium Xpath Tutorials - Identifying xpath for element with examples to use in selenium

    Xpath in selenium is close to must required. XPath is element locator and you need to provide xpath ...

  3. https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/

        https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/ ...

  4. (转载)SQL Reporting Services (Expression Examples)

    https://msdn.microsoft.com/en-us/library/ms157328(v=SQL.100).aspx Expressions are used frequently in ...

  5. Examples of MIB Variables - SNMP Tutorial

    30.5 Examples of MIB Variables Versions 1 and 2 of SNMP each collected variables together in a singl ...

  6. DataBinding examples

    Databinding in Windows Forms demo (CSWinFormDataBinding) /************************************* Modu ...

  7. https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform

    https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform

  8. Bootstrap Table Examples

    The examples of bootstrap table http://bootstrap-table.wenzhixin.net.cn/examples/ http://www.jq22.co ...

  9. RSpec shared examples with template methods

    It’s pretty common to have multiple tests that are nearly the same. In one app, we support bidding o ...

随机推荐

  1. iOS 数据序列化,NSCoding, NSCoder

    iOS可以利用NSKeyedArchiver类将对象序列化成NSData存储在磁盘上,但前提是该对象所属的类必须遵从NSCoding协议. NSCoding协议包含两个方法,要序列化的类必须实现它们 ...

  2. 多层iframe的页面取子标签

    <iframe src=''> <iframe src=''> <iframe src=''> <div></div></iframe ...

  3. PHP实现异步调用方法研究

    作者: Laruence 本文地址: http://www.laruence.com/2008/04/14/318.html 转载请注明出处 , ,); curl_setopt_array(, ); ...

  4. unity5.0新功能

    原作者 只待苍霞 章节1: 先来两个最关心的新功能, 第一章先讲PBS, 第二章讲光影GI.说到PBS, 首先应该想到的是Unity自带的两个新的Shader, 分别是Standard以及Standa ...

  5. myeclicps开发web时候复制一个工程改名字后执行出现404错误

    当部署的时候会出现如下的警告,此时请按照如下的方法解决: 1.选择要运行的工程,右击-->properties-->在上边的搜索框中搜索web,选中web,将Web Context-roo ...

  6. 遭遇flash播放mp3诡异问题

    在部分ie10+flash player 播放mp3,播放第二句话时,中断无法正常播放,(客户的机器上),自己公司的机器测试了几个,都没发现这个问题.其它浏览器(chrome,firefox)也没发现 ...

  7. js手机号码和电话号码验证正则表达式

    /******************** 函数名称:IsTelephone 函数功能:固话,手机号码检查函数,合法返回true,反之,返回false 函数参数:obj,待检查的号码 检查规则: (1 ...

  8. iOS开发中多线程间关于锁的使用

    为什么需要使用锁,当然熟悉多线程的你,自然不会感到陌生. 那你在代码中是否很好的使用了锁的机制呢?你又知道几种实现锁的方法呢? main.m 1 int main(int argc, const ch ...

  9. vs2012启动网站调试提示 HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容

    启动vs2012调试网站的时候提示: HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容. 最可能的原因: 没有为请求的 URL 配置默认文档,并且没有在服 ...

  10. CSS 多浏览器兼容性问题及解决方案

    兼容性处理要点1.DOCTYPE 影响 CSS 处理 2.FF: 设置 padding 后, div 会增加 height 和 width, 但 IE 不会, 故需要用 !important 多设一个 ...